Coverage Report

Created: 2025-10-27 03:38

/home/runner/work/slang/slang/build/source/slang-core-module/core-module-meta/hlsl.meta.slang.h
Line
Count
Source (jump to first uncovered line)
1
0
SLANG_RAW("// Slang HLSL compatibility library\n")
2
0
SLANG_RAW("//@hidden:\n")
3
0
SLANG_RAW("\n")
4
0
SLANG_RAW("typedef uint UINT;\n")
5
0
SLANG_RAW("\n")
6
0
SLANG_RAW("__intrinsic_op(")
7
0
SLANG_SPLICE(kIROp_RequireTargetExtension
8
0
)
9
0
SLANG_RAW(")\n")
10
0
SLANG_RAW("void __requireTargetExtension(constexpr String extensionName);\n")
11
0
SLANG_RAW("\n")
12
0
SLANG_RAW("/// Built-in values or system value semantics represented as in/out global variables.\n")
13
0
SLANG_RAW("/// This allows the built-ins to be arbitrarily used from a global scope without being\n")
14
0
SLANG_RAW("/// explicitly passed as entry point parameters.\n")
15
0
SLANG_RAW("in uint __builtinWaveLaneIndex : SV_WaveLaneIndex;\n")
16
0
SLANG_RAW("in uint __builtinWaveLaneCount : SV_WaveLaneCount;\n")
17
0
SLANG_RAW("in uint __builtinQuadLaneIndex : SV_QuadLaneIndex;\n")
18
0
SLANG_RAW("\n")
19
0
SLANG_RAW("//@public:\n")
20
0
SLANG_RAW("/// Represents an interface for buffer data layout.\n")
21
0
SLANG_RAW("/// This interface is used as a base for defining specific data layouts for buffers.\n")
22
0
SLANG_RAW("[sealed]\n")
23
0
SLANG_RAW("[builtin]\n")
24
0
SLANG_RAW("__magic_type(IBufferDataLayoutType)\n")
25
0
SLANG_RAW("interface IBufferDataLayout\n")
26
0
SLANG_RAW("{\n")
27
0
SLANG_RAW("}\n")
28
0
SLANG_RAW("\n")
29
0
SLANG_RAW("/// @category misc_types\n")
30
0
SLANG_RAW("__intrinsic_type(")
31
0
SLANG_SPLICE(kIROp_DefaultBufferLayoutType
32
0
)
33
0
SLANG_RAW(")\n")
34
0
SLANG_RAW("__magic_type(DefaultDataLayoutType)\n")
35
0
SLANG_RAW("struct DefaultDataLayout : IBufferDataLayout\n")
36
0
SLANG_RAW("{};\n")
37
0
SLANG_RAW("\n")
38
0
SLANG_RAW("/// @category misc_types\n")
39
0
SLANG_RAW("__intrinsic_type(")
40
0
SLANG_SPLICE(kIROp_Std430BufferLayoutType
41
0
)
42
0
SLANG_RAW(")\n")
43
0
SLANG_RAW("__magic_type(DefaultPushConstantDataLayoutType)\n")
44
0
SLANG_RAW("struct DefaultPushConstantDataLayout : IBufferDataLayout\n")
45
0
SLANG_RAW("{};\n")
46
0
SLANG_RAW("\n")
47
0
SLANG_RAW("/// @category misc_types\n")
48
0
SLANG_RAW("__intrinsic_type(")
49
0
SLANG_SPLICE(kIROp_Std140BufferLayoutType
50
0
)
51
0
SLANG_RAW(")\n")
52
0
SLANG_RAW("[require(spirv)]\n")
53
0
SLANG_RAW("[require(glsl)]\n")
54
0
SLANG_RAW("__magic_type(Std140DataLayoutType)\n")
55
0
SLANG_RAW("struct Std140DataLayout : IBufferDataLayout\n")
56
0
SLANG_RAW("{};\n")
57
0
SLANG_RAW("\n")
58
0
SLANG_RAW("/// @category misc_types\n")
59
0
SLANG_RAW("__intrinsic_type(")
60
0
SLANG_SPLICE(kIROp_Std430BufferLayoutType
61
0
)
62
0
SLANG_RAW(")\n")
63
0
SLANG_RAW("[require(spirv)]\n")
64
0
SLANG_RAW("[require(glsl)]\n")
65
0
SLANG_RAW("__magic_type(Std430DataLayoutType)\n")
66
0
SLANG_RAW("struct Std430DataLayout : IBufferDataLayout\n")
67
0
SLANG_RAW("{};\n")
68
0
SLANG_RAW("\n")
69
0
SLANG_RAW("/// @category misc_types\n")
70
0
SLANG_RAW("__intrinsic_type(")
71
0
SLANG_SPLICE(kIROp_ScalarBufferLayoutType
72
0
)
73
0
SLANG_RAW(")\n")
74
0
SLANG_RAW("__magic_type(ScalarDataLayoutType)\n")
75
0
SLANG_RAW("struct ScalarDataLayout : IBufferDataLayout\n")
76
0
SLANG_RAW("{};\n")
77
0
SLANG_RAW("\n")
78
0
SLANG_RAW("/// @category misc_types\n")
79
0
SLANG_RAW("__intrinsic_type(")
80
0
SLANG_SPLICE(kIROp_CBufferLayoutType
81
0
)
82
0
SLANG_RAW(")\n")
83
0
SLANG_RAW("__magic_type(CDataLayoutType)\n")
84
0
SLANG_RAW("[require(spirv)]\n")
85
0
SLANG_RAW("struct CDataLayout : IBufferDataLayout\n")
86
0
SLANG_RAW("{};\n")
87
0
SLANG_RAW("\n")
88
0
SLANG_RAW("//@hidden:\n")
89
0
SLANG_RAW("__generic<T, L : IBufferDataLayout = DefaultDataLayout>\n")
90
0
SLANG_RAW("__intrinsic_type(")
91
0
SLANG_SPLICE(kIROp_GLSLShaderStorageBufferType
92
0
)
93
0
SLANG_RAW(")\n")
94
0
SLANG_RAW("__magic_type(GLSLShaderStorageBufferType)\n")
95
0
SLANG_RAW("struct GLSLShaderStorageBuffer {}\n")
96
0
SLANG_RAW("\n")
97
0
SLANG_RAW("__generic<T,L:IBufferDataLayout>\n")
98
0
SLANG_RAW("__intrinsic_op(")
99
0
SLANG_SPLICE(kIROp_StructuredBufferGetDimensions
100
0
)
101
0
SLANG_RAW(")\n")
102
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, appendstructuredbuffer)]\n")
103
0
SLANG_RAW("uint2 __structuredBufferGetDimensions(AppendStructuredBuffer<T,L> buffer);\n")
104
0
SLANG_RAW("\n")
105
0
SLANG_RAW("__generic<T,L:IBufferDataLayout>\n")
106
0
SLANG_RAW("__intrinsic_op(")
107
0
SLANG_SPLICE(kIROp_StructuredBufferGetDimensions
108
0
)
109
0
SLANG_RAW(")\n")
110
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, consumestructuredbuffer)]\n")
111
0
SLANG_RAW("uint2 __structuredBufferGetDimensions(ConsumeStructuredBuffer<T,L> buffer);\n")
112
0
SLANG_RAW("\n")
113
0
SLANG_RAW("__intrinsic_op(")
114
0
SLANG_SPLICE(kIROp_StructuredBufferGetDimensions
115
0
)
116
0
SLANG_RAW(")\n")
117
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer)]\n")
118
0
SLANG_RAW("uint2 __structuredBufferGetDimensions<T,L:IBufferDataLayout>(StructuredBuffer<T,L> buffer);\n")
119
0
SLANG_RAW("\n")
120
0
SLANG_RAW("__intrinsic_op(")
121
0
SLANG_SPLICE(kIROp_StructuredBufferGetDimensions
122
0
)
123
0
SLANG_RAW(")\n")
124
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer_rw)]\n")
125
0
SLANG_RAW("uint2 __structuredBufferGetDimensions<T,L:IBufferDataLayout>(RWStructuredBuffer<T,L> buffer);\n")
126
0
SLANG_RAW("\n")
127
0
SLANG_RAW("__intrinsic_op(")
128
0
SLANG_SPLICE(kIROp_StructuredBufferGetDimensions
129
0
)
130
0
SLANG_RAW(")\n")
131
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer_rw)]\n")
132
0
SLANG_RAW("uint2 __structuredBufferGetDimensions<T,L:IBufferDataLayout>(RasterizerOrderedStructuredBuffer<T,L> buffer);\n")
133
0
SLANG_RAW("\n")
134
0
SLANG_RAW("//@public:\n")
135
0
SLANG_RAW("/**\n")
136
0
SLANG_RAW("Represents an opaque handle to an append structured buffer allocated in global memory.\n")
137
0
SLANG_RAW("A structured buffer can be viewed as an array of the specified element type.\n")
138
0
SLANG_RAW("An append structure buffer internally maintains an atomic counter to keep track of the number of elements in the buffer,\n")
139
0
SLANG_RAW("and provide an atomic operation to append a new element to the buffer.\n")
140
0
SLANG_RAW(" @param T The element type of the buffer.\n")
141
0
SLANG_RAW(" @param L The memory layout of the buffer.\n")
142
0
SLANG_RAW(" @remarks\n")
143
0
SLANG_RAW("This type is supported natively when targeting HLSL.\n")
144
0
SLANG_RAW("When generating code for other targets, this type is translated into a pair or an ordinary `RWStructuredBuffer` and\n")
145
0
SLANG_RAW("a separate `RWStructuredBuffer` that holds the atomic counter.\n")
146
0
SLANG_RAW("The `L` generic parameter is used to specify the memory layout of the buffer when\n")
147
0
SLANG_RAW("generating SPIRV.\n")
148
0
SLANG_RAW("`L` must be one of `DefaultDataLayout`, `Std140DataLayout`, `Std430DataLayout` or `ScalarDataLayout`.\n")
149
0
SLANG_RAW("The default value is `DefaultDataLayout`.\n")
150
0
SLANG_RAW("When generating code for other targets, this parameter is ignored and has no effect on the generated code.\n")
151
0
SLANG_RAW(" @see `RWStructuredBuffer`, `ConsumeStructuredBuffer`, `RasterizerOrderedStructuredBuffer`.\n")
152
0
SLANG_RAW(" @category buffer_types\n")
153
0
SLANG_RAW("*/\n")
154
0
SLANG_RAW("__generic<T, L:IBufferDataLayout=DefaultDataLayout>\n")
155
0
SLANG_RAW("__magic_type(HLSLAppendStructuredBufferType)\n")
156
0
SLANG_RAW("__intrinsic_type(")
157
0
SLANG_SPLICE(kIROp_HLSLAppendStructuredBufferType
158
0
)
159
0
SLANG_RAW(")\n")
160
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, appendstructuredbuffer)]\n")
161
0
SLANG_RAW("struct AppendStructuredBuffer\n")
162
0
SLANG_RAW("{\n")
163
0
SLANG_RAW("    __intrinsic_op(")
164
0
SLANG_SPLICE(kIROp_StructuredBufferAppend
165
0
)
166
0
SLANG_RAW(")\n")
167
0
SLANG_RAW("    /// Appends a new element to the buffer.\n")
168
0
SLANG_RAW("    ///@param value The element to be appended to the buffer.\n")
169
0
SLANG_RAW("    void Append(T value);\n")
170
0
SLANG_RAW("\n")
171
0
SLANG_RAW("    /// Get information about the number of elements and stride of the buffer.\n")
172
0
SLANG_RAW("    ///@param numStructs The number of elements in the buffer.\n")
173
0
SLANG_RAW("    ///@param stride The stride of the buffer.\n")
174
0
SLANG_RAW("    [ForceInline]\n")
175
0
SLANG_RAW("    void GetDimensions(\n")
176
0
SLANG_RAW("        out uint numStructs,\n")
177
0
SLANG_RAW("        out uint stride)\n")
178
0
SLANG_RAW("    {\n")
179
0
SLANG_RAW("        let result = __structuredBufferGetDimensions(this);\n")
180
0
SLANG_RAW("        numStructs = result.x;\n")
181
0
SLANG_RAW("        stride = result.y;\n")
182
0
SLANG_RAW("    }\n")
183
0
SLANG_RAW("};\n")
184
0
SLANG_RAW("\n")
185
0
SLANG_RAW("//@public:\n")
186
0
SLANG_RAW("/**\n")
187
0
SLANG_RAW("Represents an opaque handle to a read-only buffer allocated in global memory that is indexed in bytes.\n")
188
0
SLANG_RAW("ByteAddressBuffer can be used when working with raw buffers. Raw buffer can be viewed as a bag of bits to\n")
189
0
SLANG_RAW("which you want raw access, that is, a buffer that you can conveniently access through chunks of one to\n")
190
0
SLANG_RAW("four 32-bit typeless address values.\n")
191
0
SLANG_RAW(" @remarks\n")
192
0
SLANG_RAW("This type is supported natively when targeting HLSL.\n")
193
0
SLANG_RAW("For all other targets, this type maps to a buffer of 32bit unsigned integers.\n")
194
0
SLANG_RAW(" @category buffer_types\n")
195
0
SLANG_RAW("*/\n")
196
0
SLANG_RAW("__magic_type(HLSLByteAddressBufferType)\n")
197
0
SLANG_RAW("__intrinsic_type(")
198
0
SLANG_SPLICE(kIROp_HLSLByteAddressBufferType
199
0
)
200
0
SLANG_RAW(")\n")
201
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer)]\n")
202
0
SLANG_RAW("struct ByteAddressBuffer\n")
203
0
SLANG_RAW("{\n")
204
0
SLANG_RAW("    /// Get the number of bytes in the buffer.\n")
205
0
SLANG_RAW("    ///@param[out] dim The number of bytes in the buffer.\n")
206
0
SLANG_RAW("    [__readNone]\n")
207
0
SLANG_RAW("    [ForceInline]\n")
208
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer)]\n")
209
0
SLANG_RAW("    void GetDimensions(out uint dim)\n")
210
0
SLANG_RAW("    {\n")
211
0
SLANG_RAW("        __target_switch\n")
212
0
SLANG_RAW("        {\n")
213
0
SLANG_RAW("        case cpp: __intrinsic_asm \".GetDimensions\";\n")
214
0
SLANG_RAW("        case cuda: __intrinsic_asm \".GetDimensions\";\n")
215
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetDimensions\";\n")
216
0
SLANG_RAW("        default:\n")
217
0
SLANG_RAW("            dim = __structuredBufferGetDimensions(__getEquivalentStructuredBuffer<uint>(this)).x*4;\n")
218
0
SLANG_RAW("        }\n")
219
0
SLANG_RAW("    }\n")
220
0
SLANG_RAW("\n")
221
0
SLANG_RAW("    /// Load a 32-bit unsigned integer or value with type of `T` from the buffer at the specified location.\n")
222
0
SLANG_RAW("    ///@param T The type of the value to load from the buffer.\n")
223
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of 4.\n")
224
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
225
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
226
0
SLANG_RAW("    ///@return The value loaded from the buffer.\n")
227
0
SLANG_RAW("    ///\n")
228
0
SLANG_RAW("    ///@remarks\n")
229
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
230
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
231
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
232
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
233
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
234
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
235
0
SLANG_RAW("    [__readNone]\n")
236
0
SLANG_RAW("    [ForceInline]\n")
237
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
238
0
SLANG_RAW("    uint Load(int location)\n")
239
0
SLANG_RAW("    {\n")
240
0
SLANG_RAW("        __target_switch\n")
241
0
SLANG_RAW("        {\n")
242
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
243
0
SLANG_RAW("        default:\n")
244
0
SLANG_RAW("            return __byteAddressBufferLoad<uint>(this, uint(location), 0);\n")
245
0
SLANG_RAW("        }\n")
246
0
SLANG_RAW("    }\n")
247
0
SLANG_RAW("\n")
248
0
SLANG_RAW("    [__readNone]\n")
249
0
SLANG_RAW("    [ForceInline]\n")
250
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer)]\n")
251
0
SLANG_RAW("    uint Load(int location, out uint status)\n")
252
0
SLANG_RAW("    {\n")
253
0
SLANG_RAW("        __target_switch\n")
254
0
SLANG_RAW("        {\n")
255
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
256
0
SLANG_RAW("        }\n")
257
0
SLANG_RAW("    }\n")
258
0
SLANG_RAW("\n")
259
0
SLANG_RAW("    /// Load two 32-bit unsigned integers from the buffer at the specified location\n")
260
0
SLANG_RAW("    /// with additional alignment.\n")
261
0
SLANG_RAW("    ///@param location The input address in bytes.\n")
262
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
263
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
264
0
SLANG_RAW("    ///@return Two 32-bit unsigned integers loaded from the buffer.\n")
265
0
SLANG_RAW("    ///\n")
266
0
SLANG_RAW("    ///@remarks\n")
267
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
268
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
269
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
270
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
271
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
272
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
273
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
274
0
SLANG_RAW("    [__readNone]\n")
275
0
SLANG_RAW("    [ForceInline]\n")
276
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
277
0
SLANG_RAW("    uint2 Load2(uint location)\n")
278
0
SLANG_RAW("    {\n")
279
0
SLANG_RAW("        __target_switch\n")
280
0
SLANG_RAW("        {\n")
281
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
282
0
SLANG_RAW("        default:\n")
283
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, 0);\n")
284
0
SLANG_RAW("        }\n")
285
0
SLANG_RAW("    }\n")
286
0
SLANG_RAW("\n")
287
0
SLANG_RAW("    [__readNone]\n")
288
0
SLANG_RAW("    [ForceInline]\n")
289
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
290
0
SLANG_RAW("    uint2 Load2Aligned(uint location, uint alignment)\n")
291
0
SLANG_RAW("    {\n")
292
0
SLANG_RAW("        __target_switch\n")
293
0
SLANG_RAW("        {\n")
294
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
295
0
SLANG_RAW("        default:\n")
296
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, alignment);\n")
297
0
SLANG_RAW("        }\n")
298
0
SLANG_RAW("    }\n")
299
0
SLANG_RAW("\n")
300
0
SLANG_RAW("    [__readNone]\n")
301
0
SLANG_RAW("    [ForceInline]\n")
302
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer)]\n")
303
0
SLANG_RAW("    uint2 Load2(uint location, out uint status)\n")
304
0
SLANG_RAW("    {\n")
305
0
SLANG_RAW("        __target_switch\n")
306
0
SLANG_RAW("        {\n")
307
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
308
0
SLANG_RAW("        }\n")
309
0
SLANG_RAW("    }\n")
310
0
SLANG_RAW("\n")
311
0
SLANG_RAW("    /// Load two 32-bit unsigned integers from the buffer at the specified location with alignment\n")
312
0
SLANG_RAW("    /// of stride of `uint2`, which is 8.\n")
313
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of alignment of 8. Invalid\n")
314
0
SLANG_RAW("    /// value of location will cause undefined behavior.\n")
315
0
SLANG_RAW("    ///@return `uint2` Two 32-bit unsigned integers loaded from the buffer.\n")
316
0
SLANG_RAW("    [__readNone]\n")
317
0
SLANG_RAW("    [ForceInline]\n")
318
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
319
0
SLANG_RAW("    uint2 Load2Aligned(uint location)\n")
320
0
SLANG_RAW("    {\n")
321
0
SLANG_RAW("        __target_switch\n")
322
0
SLANG_RAW("        {\n")
323
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
324
0
SLANG_RAW("        default:\n")
325
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, __naturalStrideOf<uint2>());\n")
326
0
SLANG_RAW("        }\n")
327
0
SLANG_RAW("    }\n")
328
0
SLANG_RAW("\n")
329
0
SLANG_RAW("    /// Load three 32-bit unsigned integers from the buffer at the specified location.\n")
330
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of 4.\n")
331
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
332
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
333
0
SLANG_RAW("    ///@return `uint3` Three 32-bit unsigned integer value loaded from the buffer.\n")
334
0
SLANG_RAW("    ///\n")
335
0
SLANG_RAW("    ///@remarks\n")
336
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
337
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
338
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
339
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
340
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
341
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
342
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
343
0
SLANG_RAW("    [__readNone]\n")
344
0
SLANG_RAW("    [ForceInline]\n")
345
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
346
0
SLANG_RAW("    uint3 Load3(uint location)\n")
347
0
SLANG_RAW("    {\n")
348
0
SLANG_RAW("        __target_switch\n")
349
0
SLANG_RAW("        {\n")
350
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
351
0
SLANG_RAW("        default:\n")
352
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, 0);\n")
353
0
SLANG_RAW("        }\n")
354
0
SLANG_RAW("    }\n")
355
0
SLANG_RAW("\n")
356
0
SLANG_RAW("    [__readNone]\n")
357
0
SLANG_RAW("    [ForceInline]\n")
358
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
359
0
SLANG_RAW("    uint3 Load3Aligned(uint location, uint alignment)\n")
360
0
SLANG_RAW("    {\n")
361
0
SLANG_RAW("        __target_switch\n")
362
0
SLANG_RAW("        {\n")
363
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
364
0
SLANG_RAW("        default:\n")
365
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, alignment);\n")
366
0
SLANG_RAW("        }\n")
367
0
SLANG_RAW("    }\n")
368
0
SLANG_RAW("\n")
369
0
SLANG_RAW("    [__readNone]\n")
370
0
SLANG_RAW("    [ForceInline]\n")
371
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer)]\n")
372
0
SLANG_RAW("    uint3 Load3(uint location, out uint status)\n")
373
0
SLANG_RAW("    {\n")
374
0
SLANG_RAW("        __target_switch\n")
375
0
SLANG_RAW("        {\n")
376
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
377
0
SLANG_RAW("        }\n")
378
0
SLANG_RAW("    }\n")
379
0
SLANG_RAW("\n")
380
0
SLANG_RAW("    /// Load three 32-bit unsigned integers from the buffer at the specified location with alignment\n")
381
0
SLANG_RAW("    /// of stride of `uint3`, which is 12.\n")
382
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 12.\n")
383
0
SLANG_RAW("    ///@return `uint3` Three 32-bit unsigned integer value loaded from the buffer.\n")
384
0
SLANG_RAW("    [__readNone]\n")
385
0
SLANG_RAW("    [ForceInline]\n")
386
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
387
0
SLANG_RAW("    uint3 Load3Aligned(uint location)\n")
388
0
SLANG_RAW("    {\n")
389
0
SLANG_RAW("        __target_switch\n")
390
0
SLANG_RAW("        {\n")
391
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
392
0
SLANG_RAW("        default:\n")
393
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, __naturalStrideOf<uint3>());\n")
394
0
SLANG_RAW("        }\n")
395
0
SLANG_RAW("    }\n")
396
0
SLANG_RAW("\n")
397
0
SLANG_RAW("    /// Load four 32-bit unsigned integers from the buffer at the specified location.\n")
398
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 4.\n")
399
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
400
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
401
0
SLANG_RAW("    ///@return `uint4` Four 32-bit unsigned integer value loaded from the buffer.\n")
402
0
SLANG_RAW("    ///\n")
403
0
SLANG_RAW("    ///@remarks\n")
404
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
405
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
406
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
407
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
408
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
409
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
410
0
SLANG_RAW("    [__readNone]\n")
411
0
SLANG_RAW("    [ForceInline]\n")
412
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
413
0
SLANG_RAW("    uint4 Load4(uint location)\n")
414
0
SLANG_RAW("    {\n")
415
0
SLANG_RAW("        __target_switch\n")
416
0
SLANG_RAW("        {\n")
417
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
418
0
SLANG_RAW("        default:\n")
419
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, 0);\n")
420
0
SLANG_RAW("        }\n")
421
0
SLANG_RAW("    }\n")
422
0
SLANG_RAW("\n")
423
0
SLANG_RAW("    [__readNone]\n")
424
0
SLANG_RAW("    [ForceInline]\n")
425
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
426
0
SLANG_RAW("    uint4 Load4Aligned(uint location, uint alignment)\n")
427
0
SLANG_RAW("    {\n")
428
0
SLANG_RAW("        __target_switch\n")
429
0
SLANG_RAW("        {\n")
430
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
431
0
SLANG_RAW("        default:\n")
432
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, alignment);\n")
433
0
SLANG_RAW("        }\n")
434
0
SLANG_RAW("    }\n")
435
0
SLANG_RAW("\n")
436
0
SLANG_RAW("    [__readNone]\n")
437
0
SLANG_RAW("    [ForceInline]\n")
438
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer)]\n")
439
0
SLANG_RAW("    uint4 Load4(uint location, out uint status)\n")
440
0
SLANG_RAW("    {\n")
441
0
SLANG_RAW("        __target_switch\n")
442
0
SLANG_RAW("        {\n")
443
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
444
0
SLANG_RAW("        }\n")
445
0
SLANG_RAW("    }\n")
446
0
SLANG_RAW("\n")
447
0
SLANG_RAW("    /// Load four 32-bit unsigned integers from the buffer at the specified location with alignment\n")
448
0
SLANG_RAW("    /// of `uint4`, which is 16.\n")
449
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 16.\n")
450
0
SLANG_RAW("    ///@return `uint4` Four 32-bit unsigned integer value loaded from the buffer.\n")
451
0
SLANG_RAW("    [__readNone]\n")
452
0
SLANG_RAW("    [ForceInline]\n")
453
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv, byteaddressbuffer)]\n")
454
0
SLANG_RAW("    uint4 Load4Aligned(uint location)\n")
455
0
SLANG_RAW("    {\n")
456
0
SLANG_RAW("        __target_switch\n")
457
0
SLANG_RAW("        {\n")
458
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
459
0
SLANG_RAW("        default:\n")
460
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, __naturalStrideOf<uint4>());\n")
461
0
SLANG_RAW("        }\n")
462
0
SLANG_RAW("    }\n")
463
0
SLANG_RAW("\n")
464
0
SLANG_RAW("    [__readNone]\n")
465
0
SLANG_RAW("    [ForceInline]\n")
466
0
SLANG_RAW("    T Load<T>(uint location)\n")
467
0
SLANG_RAW("    {\n")
468
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, 0);\n")
469
0
SLANG_RAW("    }\n")
470
0
SLANG_RAW("\n")
471
0
SLANG_RAW("    [__readNone]\n")
472
0
SLANG_RAW("    [ForceInline]\n")
473
0
SLANG_RAW("    T LoadAligned<T>(uint location, uint alignment)\n")
474
0
SLANG_RAW("    {\n")
475
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, alignment);\n")
476
0
SLANG_RAW("    }\n")
477
0
SLANG_RAW("\n")
478
0
SLANG_RAW("    /// Load an element with type `T` from the buffer at the specified location with alignment of `T`.\n")
479
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiply of size of `T`.\n")
480
0
SLANG_RAW("    ///@return T value with type `T` loaded from the buffer.\n")
481
0
SLANG_RAW("    ///@remarks\n")
482
0
SLANG_RAW("    ///Currently, this function only supports when `T` is scalar, vector or matrix type.\n")
483
0
SLANG_RAW("    [__readNone]\n")
484
0
SLANG_RAW("    [ForceInline]\n")
485
0
SLANG_RAW("    T LoadAligned<T>(uint location)\n")
486
0
SLANG_RAW("    {\n")
487
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, __naturalStrideOf<T>());\n")
488
0
SLANG_RAW("    }\n")
489
0
SLANG_RAW("};\n")
490
0
SLANG_RAW("\n")
491
0
SLANG_RAW("// Texture\n")
492
0
SLANG_RAW("\n")
493
0
SLANG_RAW("/// Represent a texture shape type that can be used to specify the shape of a texture.\n")
494
0
SLANG_RAW("/// Used for the `Shape` parameter of the `_Texture` type.\n")
495
0
SLANG_RAW("///\n")
496
0
SLANG_RAW("/// Implemented by `__Shape1D`, `__Shape2D`, `__Shape3D`, `__ShapeCube` and `__ShapeBuffer`.\n")
497
0
SLANG_RAW("/// @see `_Texture`.\n")
498
0
SLANG_RAW("/// @internal\n")
499
0
SLANG_RAW("[sealed]\n")
500
0
SLANG_RAW("[builtin]\n")
501
0
SLANG_RAW("interface __ITextureShape\n")
502
0
SLANG_RAW("{\n")
503
0
SLANG_RAW("    static const int flavor;\n")
504
0
SLANG_RAW("    static const int dimensions;\n")
505
0
SLANG_RAW("    static const int planeDimensions;\n")
506
0
SLANG_RAW("}\n")
507
0
SLANG_RAW("\n")
508
0
SLANG_RAW("/// Represent a 1D, 2D or 3D texture shape that can be used as the `Shape` parameter of the `_Texture` type.\n")
509
0
SLANG_RAW("///\n")
510
0
SLANG_RAW("/// Implemented by `__Shape1D`, `__Shape2D` and `__Shape3D`.\n")
511
0
SLANG_RAW("/// @see `_Texture`.\n")
512
0
SLANG_RAW("/// @internal\n")
513
0
SLANG_RAW("[sealed]\n")
514
0
SLANG_RAW("[builtin]\n")
515
0
SLANG_RAW("interface __ITextureShape1D2D3D : __ITextureShape\n")
516
0
SLANG_RAW("{\n")
517
0
SLANG_RAW("}\n")
518
0
SLANG_RAW("\n")
519
0
SLANG_RAW("/// When used as the `Shape` parameter of the `_Texture` type, specifies a 1D texture.\n")
520
0
SLANG_RAW("/// @category misc_types Miscelaneous types\n")
521
0
SLANG_RAW("__magic_type(TextureShape1DType)\n")
522
0
SLANG_RAW("__intrinsic_type(")
523
0
SLANG_SPLICE(kIROp_TextureShape1DType
524
0
)
525
0
SLANG_RAW(")\n")
526
0
SLANG_RAW("struct __Shape1D : __ITextureShape1D2D3D\n")
527
0
SLANG_RAW("{\n")
528
0
SLANG_RAW("    static const int flavor = ")
529
0
SLANG_SPLICE(SLANG_TEXTURE_1D
530
0
)
531
0
SLANG_RAW(";\n")
532
0
SLANG_RAW("    static const int dimensions = 1;\n")
533
0
SLANG_RAW("    static const int planeDimensions = 1;\n")
534
0
SLANG_RAW("}\n")
535
0
SLANG_RAW("\n")
536
0
SLANG_RAW("/// When used as the `Shape` parameter of the `_Texture` type, specifies a 2D texture.\n")
537
0
SLANG_RAW("/// @category misc_types\n")
538
0
SLANG_RAW("__magic_type(TextureShape2DType)\n")
539
0
SLANG_RAW("__intrinsic_type(")
540
0
SLANG_SPLICE(kIROp_TextureShape2DType
541
0
)
542
0
SLANG_RAW(")\n")
543
0
SLANG_RAW("struct __Shape2D : __ITextureShape1D2D3D\n")
544
0
SLANG_RAW("{\n")
545
0
SLANG_RAW("    static const int flavor = ")
546
0
SLANG_SPLICE(SLANG_TEXTURE_2D
547
0
)
548
0
SLANG_RAW(";\n")
549
0
SLANG_RAW("    static const int dimensions = 2;\n")
550
0
SLANG_RAW("    static const int planeDimensions = 2;\n")
551
0
SLANG_RAW("}\n")
552
0
SLANG_RAW("\n")
553
0
SLANG_RAW("/// When used as the `Shape` parameter of the `_Texture` type, specifies a 3D texture.\n")
554
0
SLANG_RAW("/// @category misc_types\n")
555
0
SLANG_RAW("__magic_type(TextureShape3DType)\n")
556
0
SLANG_RAW("__intrinsic_type(")
557
0
SLANG_SPLICE(kIROp_TextureShape3DType
558
0
)
559
0
SLANG_RAW(")\n")
560
0
SLANG_RAW("struct __Shape3D : __ITextureShape1D2D3D\n")
561
0
SLANG_RAW("{\n")
562
0
SLANG_RAW("    static const int flavor = ")
563
0
SLANG_SPLICE(SLANG_TEXTURE_3D
564
0
)
565
0
SLANG_RAW(";\n")
566
0
SLANG_RAW("    static const int dimensions = 3;\n")
567
0
SLANG_RAW("    static const int planeDimensions = 3;\n")
568
0
SLANG_RAW("}\n")
569
0
SLANG_RAW("\n")
570
0
SLANG_RAW("/// When used as the `Shape` parameter of the `_Texture` type, specifies a Cube texture.\n")
571
0
SLANG_RAW("/// @category misc_types\n")
572
0
SLANG_RAW("__magic_type(TextureShapeCubeType)\n")
573
0
SLANG_RAW("__intrinsic_type(")
574
0
SLANG_SPLICE(kIROp_TextureShapeCubeType
575
0
)
576
0
SLANG_RAW(")\n")
577
0
SLANG_RAW("struct __ShapeCube : __ITextureShape\n")
578
0
SLANG_RAW("{\n")
579
0
SLANG_RAW("    static const int flavor = ")
580
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
581
0
)
582
0
SLANG_RAW(";\n")
583
0
SLANG_RAW("    static const int dimensions = 3;\n")
584
0
SLANG_RAW("    static const int planeDimensions = 2;\n")
585
0
SLANG_RAW("}\n")
586
0
SLANG_RAW("\n")
587
0
SLANG_RAW("/// When used as the `Shape` parameter of the `_Texture` type, specifies a buffer texture.\n")
588
0
SLANG_RAW("/// @category misc_types\n")
589
0
SLANG_RAW("__magic_type(TextureShapeBufferType)\n")
590
0
SLANG_RAW("__intrinsic_type(")
591
0
SLANG_SPLICE(kIROp_TextureShapeBufferType
592
0
)
593
0
SLANG_RAW(")\n")
594
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv)]\n")
595
0
SLANG_RAW("struct __ShapeBuffer : __ITextureShape\n")
596
0
SLANG_RAW("{\n")
597
0
SLANG_RAW("    static const int flavor = ")
598
0
SLANG_SPLICE(SLANG_TEXTURE_BUFFER
599
0
)
600
0
SLANG_RAW(";\n")
601
0
SLANG_RAW("    static const int dimensions = 1;\n")
602
0
SLANG_RAW("    static const int planeDimensions = 1;\n")
603
0
SLANG_RAW("}\n")
604
0
SLANG_RAW("\n")
605
0
SLANG_RAW("//@hidden:\n")
606
0
SLANG_RAW("__intrinsic_op(vectorReshape)\n")
607
0
SLANG_RAW("vector<T,N> __vectorReshape<let N : int, T, let M : int>(vector<T,M> vin);\n")
608
0
SLANG_RAW("\n")
609
0
SLANG_RAW("__intrinsic_op(makeVector)\n")
610
0
SLANG_RAW("__generic<T, let N:int>\n")
611
0
SLANG_RAW("vector<T,N+1> __makeVector(vector<T,N> vec, T scalar);\n")
612
0
SLANG_RAW("\n")
613
0
SLANG_RAW("//@public:\n")
614
0
SLANG_RAW("/// Represent types that can be used as texel element.\n")
615
0
SLANG_RAW("[sealed]\n")
616
0
SLANG_RAW("[builtin]\n")
617
0
SLANG_RAW("interface ITexelElement\n")
618
0
SLANG_RAW("{\n")
619
0
SLANG_RAW("    associatedtype Element : __BuiltinArithmeticType;\n")
620
0
SLANG_RAW("    static const int elementCount;\n")
621
0
SLANG_RAW("    [OverloadRank(-1)]\n")
622
0
SLANG_RAW("    __init(Element x);\n")
623
0
SLANG_RAW("}\n")
624
0
SLANG_RAW("\n")
625
0
SLANG_RAW("extension<T:__BuiltinArithmeticType> T : ITexelElement\n")
626
0
SLANG_RAW("{\n")
627
0
SLANG_RAW("    typealias Element = T;\n")
628
0
SLANG_RAW("    static const int elementCount = 1;\n")
629
0
SLANG_RAW("    __intrinsic_op(0) __init(Element x);\n")
630
0
SLANG_RAW("}\n")
631
0
SLANG_RAW("\n")
632
633
// Scalar types that can be used as texel element.
634
0
const char* texeElementScalarTypes[] = {
635
0
    "half",
636
0
    "float",
637
0
    "int",
638
0
    "uint",
639
0
    "int8_t",
640
0
    "int16_t",
641
0
    "uint8_t",
642
0
    "uint16_t"
643
0
};
644
0
for (auto elementType : texeElementScalarTypes)
645
0
{
646
0
SLANG_RAW("#line 568 \"hlsl.meta.slang\"")
647
0
SLANG_RAW("\n")
648
0
SLANG_RAW("extension<int N> vector<")
649
0
SLANG_SPLICE(elementType
650
0
)
651
0
SLANG_RAW(", N> : ITexelElement\n")
652
0
SLANG_RAW("{\n")
653
0
SLANG_RAW("    typealias Element = ")
654
0
SLANG_SPLICE(elementType
655
0
)
656
0
SLANG_RAW(";\n")
657
0
SLANG_RAW("    static const int elementCount = N;\n")
658
0
SLANG_RAW("    __intrinsic_op(")
659
0
SLANG_SPLICE(kIROp_MakeVectorFromScalar
660
0
)
661
0
SLANG_RAW(") __init(Element x);\n")
662
0
SLANG_RAW("}\n")
663
664
0
} // end for texelElementScalarTypes.
665
0
SLANG_RAW("#line 577 \"hlsl.meta.slang\"")
666
0
SLANG_RAW("\n")
667
0
SLANG_RAW("\n")
668
0
SLANG_RAW("// Additional 64-bit types that can be used as texel element.\n")
669
0
SLANG_RAW("extension double:ITexelElement\n")
670
0
SLANG_RAW("{\n")
671
0
SLANG_RAW("    typealias Element = double;\n")
672
0
SLANG_RAW("    static const int elementCount = 1;\n")
673
0
SLANG_RAW("    __intrinsic_op(0) __init(Element x);\n")
674
0
SLANG_RAW("}\n")
675
0
SLANG_RAW("extension double2:ITexelElement\n")
676
0
SLANG_RAW("{\n")
677
0
SLANG_RAW("    typealias Element = double;\n")
678
0
SLANG_RAW("    static const int elementCount = 2;\n")
679
0
SLANG_RAW("    __intrinsic_op(")
680
0
SLANG_SPLICE(kIROp_MakeVectorFromScalar
681
0
)
682
0
SLANG_RAW(") __init(Element x);\n")
683
0
SLANG_RAW("}\n")
684
0
SLANG_RAW("extension uint64_t:ITexelElement\n")
685
0
SLANG_RAW("{\n")
686
0
SLANG_RAW("    typealias Element = uint64_t;\n")
687
0
SLANG_RAW("    static const int elementCount = 1;\n")
688
0
SLANG_RAW("    __intrinsic_op(0) __init(Element x);\n")
689
0
SLANG_RAW("}\n")
690
0
SLANG_RAW("extension int64_t:ITexelElement\n")
691
0
SLANG_RAW("{\n")
692
0
SLANG_RAW("    typealias Element = int64_t;\n")
693
0
SLANG_RAW("    static const int elementCount = 1;\n")
694
0
SLANG_RAW("    __intrinsic_op(0) __init(Element x);\n")
695
0
SLANG_RAW("}\n")
696
0
SLANG_RAW("extension vector<uint64_t,2>:ITexelElement\n")
697
0
SLANG_RAW("{\n")
698
0
SLANG_RAW("    typealias Element = uint64_t;\n")
699
0
SLANG_RAW("    static const int elementCount = 2;\n")
700
0
SLANG_RAW("    __intrinsic_op(")
701
0
SLANG_SPLICE(kIROp_MakeVectorFromScalar
702
0
)
703
0
SLANG_RAW(") __init(Element x);\n")
704
0
SLANG_RAW("}\n")
705
0
SLANG_RAW("extension vector<int64_t,2>:ITexelElement\n")
706
0
SLANG_RAW("{\n")
707
0
SLANG_RAW("    typealias Element = int64_t;\n")
708
0
SLANG_RAW("    static const int elementCount = 2;\n")
709
0
SLANG_RAW("    __intrinsic_op(")
710
0
SLANG_SPLICE(kIROp_MakeVectorFromScalar
711
0
)
712
0
SLANG_RAW(") __init(Element x);\n")
713
0
SLANG_RAW("}\n")
714
0
SLANG_RAW("\n")
715
0
SLANG_RAW("//@public:\n")
716
0
SLANG_RAW("/// A parameterized type that represents all flavors of texture types supported by the Slang language.\n")
717
0
SLANG_RAW("/// Please note that this type is not intended to be used directly in user code, and not all combinations\n")
718
0
SLANG_RAW("/// of the generic arguments are valid.\n")
719
0
SLANG_RAW("/// Instead, use the specific texture types such as `Texture1D`, `Texture2DArray` and `Sampler2D` etc.\n")
720
0
SLANG_RAW("/// This documentation is provided for reference purposes only.\n")
721
0
SLANG_RAW("/// @param T The element type of the texture. Must be a scalar or vector type.\n")
722
0
SLANG_RAW("/// @param Shape The shape of the texture. Must be one of `__Shape1D`, `__Shape2D`, `__Shape3D`, `__ShapeCube` or `__ShapeBuffer`.\n")
723
0
SLANG_RAW("/// @param isArray Indicates whether the texture is an array texture.\n")
724
0
SLANG_RAW("/// @param isMS Indicates whether the texture is a multisampled texture.\n")
725
0
SLANG_RAW("/// @param sampleCount The number of samples of a multisampled texture.\n")
726
0
SLANG_RAW("/// @param access The access mode of the texture. 0 for read-only, 1 for read-write, 2 for rasterizer-ordered, 3 for feedback.\n")
727
0
SLANG_RAW("/// @param isShadow Indicates whether the texture is a shadow texture (for combined texture-sampler only).\n")
728
0
SLANG_RAW("/// @param isCombined Indicates whether the texture is a combined texture-sampler.\n")
729
0
SLANG_RAW("/// @param format The storage format of the texture. Users should specify the format using an `[format(\"...\")]` attribute instead.\n")
730
0
SLANG_RAW("/// @see `Texture1D`, `Texture2D`, `Texture3D`, `TextureCube`, `Texture1DArray`,\n")
731
0
SLANG_RAW("/// `Texture2DArray`, `TextureCubeArray`, `Sampler1D`, `Sampler2D`, `Sampler3D`, `SamplerCube`, `Sampler1DArray`, `Sampler2DArray`, `SamplerCubeArray`,\n")
732
0
SLANG_RAW("/// `Texture2DMS`, `Texture2DMSArray`, `RWTexture1D`, `RWTexture2D`, `RWTexture3D`, `RWTexture1DArray`, `RWTexture2DArray`,\n")
733
0
SLANG_RAW("/// `RWTexture2DMS`, `RWTexture2DMSArray`, `Buffer`, `RWBuffer`, `FeedbackTexture2D`, `FeedbackTexture2DArray`.\n")
734
0
SLANG_RAW("/// @remarks\n")
735
0
SLANG_RAW("/// HLSL texture types are implemented as typealiases to the builtin `_Texture` type. Users\n")
736
0
SLANG_RAW("/// are advised to use the HLSL-specific texture types instead of `_Texture` directly.\n")
737
0
SLANG_RAW("///\n")
738
0
SLANG_RAW("/// For read-write textures, Slang will automatically infer `format` from `T`.\n")
739
0
SLANG_RAW("/// To explicitly specify texel storage formats for read-write textures,\n")
740
0
SLANG_RAW("/// use the `[format(\"formatString\")]` attribute on the texture parameter declaration.\n")
741
0
SLANG_RAW("/// Allowed `formatString` values are:\n")
742
0
SLANG_RAW("///\n")
743
0
SLANG_RAW("/// |id | Format string        | Meaning           |\n")
744
0
SLANG_RAW("/// |:--|:---------------------|:------------------|\n")
745
0
SLANG_RAW("/// |1  |`\"rgba32f\"`           | 4 channel 32-bit floating point texture |\n")
746
0
SLANG_RAW("/// |2  |`\"rgba16f\"`           | 4 channel 16-bit floating point texture |\n")
747
0
SLANG_RAW("/// |3  |`\"rg32f\"`             | 2 channel 32-bit floating point texture |\n")
748
0
SLANG_RAW("/// |4  |`\"rg16f\"`             | 2 channel 16-bit floating point texture |\n")
749
0
SLANG_RAW("/// |5  |`\"r11f_g11f_b10f\"`    | 3 channel 11/11/10-bit floating point texture |\n")
750
0
SLANG_RAW("/// |6  |`\"r32f\"`              | 1 channel 32-bit floating point texture |\n")
751
0
SLANG_RAW("/// |7  |`\"r16f\"`              | 1 channel 16-bit floating point texture |\n")
752
0
SLANG_RAW("/// |8  |`\"rgba16\"`            | 4 channel 16-bit normalized unsigned integer texture |\n")
753
0
SLANG_RAW("/// |9  |`\"rgb10_a2\"`          | 4 channel 10/10/10/2-bit normalized unsigned integer texture |\n")
754
0
SLANG_RAW("/// |10 |`\"rgba8\"`             | 4 channel 8-bit normalized unsigned integer texture |\n")
755
0
SLANG_RAW("/// |11 |`\"rg16\"`              | 2 channel 16-bit normalized unsigned integer texture |\n")
756
0
SLANG_RAW("/// |12 |`\"rg8\"`               | 2 channel 8-bit normalized unsigned integer texture |\n")
757
0
SLANG_RAW("/// |13 |`\"r16\"`               | 1 channel 16-bit normalized unsigned integer texture |\n")
758
0
SLANG_RAW("/// |14 |`\"r8\"`                | 1 channel 8-bit normalized unsigned integer texture |\n")
759
0
SLANG_RAW("/// |15 |`\"rgba16_snorm\"`      | 4 channel 16-bit normalized signed integer texture |\n")
760
0
SLANG_RAW("/// |16 |`\"rgba8_snorm\"`       | 4 channel 8-bit normalized signed integer texture |\n")
761
0
SLANG_RAW("/// |17 |`\"rg16_snorm\"`        | 2 channel 16-bit normalized signed integer texture |\n")
762
0
SLANG_RAW("/// |18 |`\"rg8_snorm\"`         | 2 channel 8-bit normalized signed integer texture |\n")
763
0
SLANG_RAW("/// |19 |`\"r16_snorm\"`         | 1 channel 16-bit normalized signed integer texture |\n")
764
0
SLANG_RAW("/// |20 |`\"r8_snorm\"`          | 1 channel 8-bit normalized signed integer texture |\n")
765
0
SLANG_RAW("/// |21 |`\"rgba32i\"`           | 4 channel 32-bit signed integer texture |\n")
766
0
SLANG_RAW("/// |22 |`\"rgba16i\"`           | 4 channel 16-bit signed integer texture |\n")
767
0
SLANG_RAW("/// |23 |`\"rgba8i\"`            | 4 channel 8-bit signed integer texture |\n")
768
0
SLANG_RAW("/// |24 |`\"rg32i\"`             | 2 channel 32-bit signed integer texture |\n")
769
0
SLANG_RAW("/// |25 |`\"rg16i\"`             | 2 channel 16-bit signed integer texture |\n")
770
0
SLANG_RAW("/// |26 |`\"rg8i\"`              | 2 channel 8-bit signed integer texture |\n")
771
0
SLANG_RAW("/// |27 |`\"r32i\"`              | 1 channel 32-bit signed integer texture |\n")
772
0
SLANG_RAW("/// |28 |`\"r16i\"`              | 1 channel 16-bit signed integer texture |\n")
773
0
SLANG_RAW("/// |29 |`\"r8i\"`               | 1 channel 8-bit signed integer texture |\n")
774
0
SLANG_RAW("/// |30 |`\"rgba32ui\"`          | 4 channel 32-bit unsigned integer texture |\n")
775
0
SLANG_RAW("/// |31 |`\"rgba16ui\"`          | 4 channel 16-bit unsigned integer texture |\n")
776
0
SLANG_RAW("/// |32 |`\"rgb10_a2ui\"`        | 4 channel 10/10/10/2-bit unsigned integer texture |\n")
777
0
SLANG_RAW("/// |33 |`\"rgba8ui\"`           | 4 channel 8-bit unsigned integer texture |\n")
778
0
SLANG_RAW("/// |34 |`\"rg32ui\"`            | 2 channel 32-bit unsigned integer texture |\n")
779
0
SLANG_RAW("/// |35 |`\"rg16ui\"`            | 2 channel 16-bit unsigned integer texture |\n")
780
0
SLANG_RAW("/// |36 |`\"rg8ui\"`             | 2 channel 8-bit unsigned integer texture |\n")
781
0
SLANG_RAW("/// |37 |`\"r32ui\"`             | 1 channel 32-bit unsigned integer texture |\n")
782
0
SLANG_RAW("/// |38 |`\"r16ui\"`             | 1 channel 16-bit unsigned integer texture |\n")
783
0
SLANG_RAW("/// |39 |`\"r8ui\"`              | 1 channel 8-bit unsigned integer texture |\n")
784
0
SLANG_RAW("/// |40 |`\"r64ui\"`             | 1 channel 64-bit unsigned integer texture |\n")
785
0
SLANG_RAW("/// |41 |`\"r64i\"`              | 1 channel 64-bit signed integer texture |\n")
786
0
SLANG_RAW("///\n")
787
0
SLANG_RAW("/// When targeting Vulkan, a combined-texture-sampler type (`isCombined==1`) translates to a `OpTypeSampledImage` type in SPIR-V.\n")
788
0
SLANG_RAW("/// For other targets, the combined-texture-sampler type is translated to a pair of a `Texture` and `SamplerState`.\n")
789
0
SLANG_RAW("/// `isShadow` is only applicable to combined-texture-sampler types and must be `0` for non-combined texture types.\n")
790
0
SLANG_RAW("/// @internal\n")
791
0
SLANG_RAW("/// @category texture_types Texture types\n")
792
0
SLANG_RAW("__magic_type(TextureType)\n")
793
0
SLANG_RAW("__intrinsic_type(")
794
0
SLANG_SPLICE(kIROp_TextureType
795
0
)
796
0
SLANG_RAW(")\n")
797
0
SLANG_RAW("struct _Texture<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
798
0
SLANG_RAW("{\n")
799
0
SLANG_RAW("}\n")
800
0
SLANG_RAW("\n")
801
0
SLANG_RAW("//@hidden:\n")
802
0
SLANG_RAW("// Combined texture sampler specific functions\n")
803
0
SLANG_RAW("\n")
804
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
805
0
SLANG_RAW("float __glsl_texture<TSampler, TCoord>(TSampler s, TCoord value)\n")
806
0
SLANG_RAW("{\n")
807
0
SLANG_RAW("    __target_switch\n")
808
0
SLANG_RAW("    {\n")
809
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($0, $1)\";\n")
810
0
SLANG_RAW("    }\n")
811
0
SLANG_RAW("}\n")
812
0
SLANG_RAW("\n")
813
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
814
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
815
0
SLANG_RAW("float __glsl_texture_1d_shadow<TSampler, TCoord>(TSampler s, TCoord value)\n")
816
0
SLANG_RAW("{\n")
817
0
SLANG_RAW("    __target_switch\n")
818
0
SLANG_RAW("    {\n")
819
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($0, $1)\";\n")
820
0
SLANG_RAW("    }\n")
821
0
SLANG_RAW("}\n")
822
0
SLANG_RAW("\n")
823
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
824
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
825
0
SLANG_RAW("float __glsl_texture_3d_array_shadow<TSampler, TCoord>(TSampler s, TCoord value, float compare)\n")
826
0
SLANG_RAW("{\n")
827
0
SLANG_RAW("    __target_switch\n")
828
0
SLANG_RAW("    {\n")
829
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($0, $1, $2)\";\n")
830
0
SLANG_RAW("    }\n")
831
0
SLANG_RAW("}\n")
832
0
SLANG_RAW("\n")
833
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
834
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
835
0
SLANG_RAW("float __glsl_texture_offset<TSampler, TCoord, TOffset>( TSampler s, TCoord value, constexpr TOffset offset)\n")
836
0
SLANG_RAW("{\n")
837
0
SLANG_RAW("    __target_switch\n")
838
0
SLANG_RAW("    {\n")
839
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureOffset($0, $1, $2)\";\n")
840
0
SLANG_RAW("    }\n")
841
0
SLANG_RAW("}\n")
842
0
SLANG_RAW("\n")
843
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
844
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
845
0
SLANG_RAW("float __glsl_texture_offset_1d_shadow<TSampler, TCoord, TOffset>(TSampler s, TCoord value, constexpr TOffset offset)\n")
846
0
SLANG_RAW("{\n")
847
0
SLANG_RAW("    __target_switch\n")
848
0
SLANG_RAW("    {\n")
849
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureOffset($0, $1, $2)\";\n")
850
0
SLANG_RAW("    }\n")
851
0
SLANG_RAW("}\n")
852
0
SLANG_RAW("\n")
853
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
854
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
855
0
SLANG_RAW("float __glsl_texture_level<TSampler, TCoord>(TSampler s, TCoord value, float level)\n")
856
0
SLANG_RAW("{\n")
857
0
SLANG_RAW("    __target_switch\n")
858
0
SLANG_RAW("    {\n")
859
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLod($0, $1, $2)\";\n")
860
0
SLANG_RAW("    }\n")
861
0
SLANG_RAW("}\n")
862
0
SLANG_RAW("\n")
863
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
864
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
865
0
SLANG_RAW("float __glsl_texture_level_1d_shadow<TSampler, TCoord>(TSampler s, TCoord value, float level)\n")
866
0
SLANG_RAW("{\n")
867
0
SLANG_RAW("    __target_switch\n")
868
0
SLANG_RAW("    {\n")
869
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLod($0, $1, $2)\";\n")
870
0
SLANG_RAW("    }\n")
871
0
SLANG_RAW("}\n")
872
0
SLANG_RAW("\n")
873
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
874
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
875
0
SLANG_RAW("float __glsl_texture_level_offset<TSampler, TCoord, TOffset>(TSampler s, TCoord value, float level, constexpr TOffset offset)\n")
876
0
SLANG_RAW("{\n")
877
0
SLANG_RAW("    __target_switch\n")
878
0
SLANG_RAW("    {\n")
879
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLodOffset($0, $1, $2, $3)\";\n")
880
0
SLANG_RAW("    }\n")
881
0
SLANG_RAW("}\n")
882
0
SLANG_RAW("\n")
883
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
884
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
885
0
SLANG_RAW("float __glsl_texture_level_offset_1d_shadow<TSampler, TCoord, TOffset>(TSampler s, TCoord value, float level, constexpr TOffset offset)\n")
886
0
SLANG_RAW("{\n")
887
0
SLANG_RAW("    __target_switch\n")
888
0
SLANG_RAW("    {\n")
889
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLodOffset($0, $1, $2, $3)\";\n")
890
0
SLANG_RAW("    }\n")
891
0
SLANG_RAW("}\n")
892
0
SLANG_RAW("\n")
893
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
894
0
SLANG_RAW("float __glsl_texture<TTexture, TCoord>(TTexture t, SamplerComparisonState s, TCoord value)\n")
895
0
SLANG_RAW("{\n")
896
0
SLANG_RAW("    __target_switch\n")
897
0
SLANG_RAW("    {\n")
898
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($p, $2)\";\n")
899
0
SLANG_RAW("    }\n")
900
0
SLANG_RAW("}\n")
901
0
SLANG_RAW("\n")
902
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
903
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
904
0
SLANG_RAW("float __glsl_texture_1d_shadow<TTexture, TCoord>(TTexture t, SamplerComparisonState s, TCoord value)\n")
905
0
SLANG_RAW("{\n")
906
0
SLANG_RAW("    __target_switch\n")
907
0
SLANG_RAW("    {\n")
908
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($p, $2)\";\n")
909
0
SLANG_RAW("    }\n")
910
0
SLANG_RAW("}\n")
911
0
SLANG_RAW("\n")
912
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
913
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
914
0
SLANG_RAW("float __glsl_texture_3d_array_shadow<TTexture, TCoord>(TTexture t, SamplerComparisonState s, TCoord value, float compare)\n")
915
0
SLANG_RAW("{\n")
916
0
SLANG_RAW("    __target_switch\n")
917
0
SLANG_RAW("    {\n")
918
0
SLANG_RAW("    case glsl: __intrinsic_asm \"texture($p, $2, $3)\";\n")
919
0
SLANG_RAW("    }\n")
920
0
SLANG_RAW("}\n")
921
0
SLANG_RAW("\n")
922
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
923
0
SLANG_RAW("float __glsl_texture_offset<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, constexpr TOffset offset)\n")
924
0
SLANG_RAW("{\n")
925
0
SLANG_RAW("    __target_switch\n")
926
0
SLANG_RAW("    {\n")
927
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureOffset($p, $2, $3)\";\n")
928
0
SLANG_RAW("    }\n")
929
0
SLANG_RAW("}\n")
930
0
SLANG_RAW("\n")
931
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
932
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
933
0
SLANG_RAW("float __glsl_texture_offset_1d_shadow<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, constexpr TOffset offset)\n")
934
0
SLANG_RAW("{\n")
935
0
SLANG_RAW("    __target_switch\n")
936
0
SLANG_RAW("    {\n")
937
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureOffset($p, $2, $3)\";\n")
938
0
SLANG_RAW("    }\n")
939
0
SLANG_RAW("}\n")
940
0
SLANG_RAW("\n")
941
0
SLANG_RAW("[require(glsl, texture_sm_4_1)]\n")
942
0
SLANG_RAW("float __glsl_texture_level<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value, float level)\n")
943
0
SLANG_RAW("{\n")
944
0
SLANG_RAW("    __target_switch\n")
945
0
SLANG_RAW("    {\n")
946
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLod($p, $2, $3)\";\n")
947
0
SLANG_RAW("    }\n")
948
0
SLANG_RAW("}\n")
949
0
SLANG_RAW("\n")
950
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
951
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
952
0
SLANG_RAW("float __glsl_texture_level_1d_shadow<TTexture, TCoord>(TTexture t,SamplerComparisonState s, TCoord value, float level)\n")
953
0
SLANG_RAW("{\n")
954
0
SLANG_RAW("    __target_switch\n")
955
0
SLANG_RAW("    {\n")
956
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLod($p, $2, $3)\";\n")
957
0
SLANG_RAW("    }\n")
958
0
SLANG_RAW("}\n")
959
0
SLANG_RAW("\n")
960
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
961
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
962
0
SLANG_RAW("float __glsl_texture_level_offset<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, float level, constexpr TOffset offset)\n")
963
0
SLANG_RAW("{\n")
964
0
SLANG_RAW("    __target_switch\n")
965
0
SLANG_RAW("    {\n")
966
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLodOffset($p, $2, $3, $4)\";\n")
967
0
SLANG_RAW("    }\n")
968
0
SLANG_RAW("}\n")
969
0
SLANG_RAW("\n")
970
0
SLANG_RAW("__glsl_extension(GL_EXT_texture_shadow_lod)\n")
971
0
SLANG_RAW("[require(glsl, texture_shadowlod)]\n")
972
0
SLANG_RAW("float __glsl_texture_level_offset_1d_shadow<TTexture, TCoord, TOffset>(TTexture t,SamplerComparisonState s, TCoord value, float level, constexpr TOffset offset)\n")
973
0
SLANG_RAW("{\n")
974
0
SLANG_RAW("    __target_switch\n")
975
0
SLANG_RAW("    {\n")
976
0
SLANG_RAW("    case glsl: __intrinsic_asm \"textureLodOffset($p, $2, $3, $4)\";\n")
977
0
SLANG_RAW("    }\n")
978
0
SLANG_RAW("}\n")
979
0
SLANG_RAW("\n")
980
0
SLANG_RAW("__intrinsic_op(")
981
0
SLANG_SPLICE(kIROp_MetalCastToDepthTexture
982
0
)
983
0
SLANG_RAW(")\n")
984
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
985
0
SLANG_RAW("_Texture<T,Shape,isArray,isMS,sampleCount,access,1,isCombined,format> __metal_asDepthTexture(_Texture<T,Shape,isArray,isMS,sampleCount,access,isShadow,isCombined,format> tex);\n")
986
0
SLANG_RAW("\n")
987
0
SLANG_RAW("[require(wgsl)]\n")
988
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
989
0
SLANG_RAW("void __wgsl_check_texture_type()\n")
990
0
SLANG_RAW("{\n")
991
0
SLANG_RAW("    // Texel element type checks\n")
992
0
SLANG_RAW("    static_assert(\n")
993
0
SLANG_RAW("        T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4> ||\n")
994
0
SLANG_RAW("        T is int   || T is vector<int,  2> || T is vector<int,  3> || T is vector<int,  4> ||\n")
995
0
SLANG_RAW("        T is uint  || T is vector<uint, 2> || T is vector<uint, 3> || T is vector<uint, 4>\n")
996
0
SLANG_RAW("        , \"WGSL supports only f32/i32/u32 type textures\");\n")
997
0
SLANG_RAW("    static_assert(isShadow == 0 || T is float\n")
998
0
SLANG_RAW("        , \"WGSL depth textures must be scalar f32\");\n")
999
0
SLANG_RAW("\n")
1000
0
SLANG_RAW("    // Array types\n")
1001
0
SLANG_RAW("    static_assert(isArray == 0 || isMS == 0\n")
1002
0
SLANG_RAW("        , \"WGSL does not support multisampled texture arrays\");\n")
1003
0
SLANG_RAW("    static_assert(isArray == 0 || Shape.flavor == ")
1004
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1005
0
)
1006
0
SLANG_RAW(" || Shape.flavor == ")
1007
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1008
0
)
1009
0
SLANG_RAW("\n")
1010
0
SLANG_RAW("        , \"WGSL array texture shape must be either 2D or Cube\");\n")
1011
0
SLANG_RAW("\n")
1012
0
SLANG_RAW("    // Depth texture shapes\n")
1013
0
SLANG_RAW("    static_assert(isShadow == 0 || Shape.flavor == ")
1014
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1015
0
)
1016
0
SLANG_RAW(" || Shape.flavor == ")
1017
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1018
0
)
1019
0
SLANG_RAW("\n")
1020
0
SLANG_RAW("        , \"WGSL depth texture shape must be either 2D or Cube\");\n")
1021
0
SLANG_RAW("\n")
1022
0
SLANG_RAW("    // Multisampled texture shapes\n")
1023
0
SLANG_RAW("    static_assert(isMS == 0 || Shape.flavor == ")
1024
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1025
0
)
1026
0
SLANG_RAW("\n")
1027
0
SLANG_RAW("        , \"WGSL multisampled texture shape must be 2D\");\n")
1028
0
SLANG_RAW("}\n")
1029
0
SLANG_RAW("\n")
1030
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
1031
0
SLANG_RAW("void __wgsl_check_texture_type_texel_offset()\n")
1032
0
SLANG_RAW("{\n")
1033
0
SLANG_RAW("     __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
1034
0
SLANG_RAW("\n")
1035
0
SLANG_RAW("     static_assert(Shape.flavor != ")
1036
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1037
0
)
1038
0
SLANG_RAW(" || Shape.flavor != ")
1039
0
SLANG_SPLICE(SLANG_TEXTURE_3D
1040
0
)
1041
0
SLANG_RAW("\n")
1042
0
SLANG_RAW("         , \"WGSL texture shape must be 2D or 3D when sampling with texel offsets\");\n")
1043
0
SLANG_RAW("}\n")
1044
0
SLANG_RAW("\n")
1045
0
SLANG_RAW("\n")
1046
0
SLANG_RAW("//@public:\n")
1047
0
SLANG_RAW("\n")
1048
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let isShadow:int, let format:int>\n")
1049
0
SLANG_RAW("extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,1,format>\n")
1050
0
SLANG_RAW("{\n")
1051
0
SLANG_RAW("    //@hidden:\n")
1052
0
SLANG_RAW("    static const int access = 0;\n")
1053
0
SLANG_RAW("\n")
1054
0
SLANG_RAW("    //@public:\n")
1055
0
SLANG_RAW("    typealias TextureCoord = vector<float, Shape.dimensions>;\n")
1056
0
SLANG_RAW("\n")
1057
0
SLANG_RAW("    __intrinsic_op(")
1058
0
SLANG_SPLICE(kIROp_CombinedTextureSamplerGetTexture
1059
0
)
1060
0
SLANG_RAW(")\n")
1061
0
SLANG_RAW("    _Texture<T, Shape, isArray, isMS, sampleCount, 0, isShadow, 0, format> __getTexture();\n")
1062
0
SLANG_RAW("\n")
1063
0
SLANG_RAW("    __intrinsic_op(")
1064
0
SLANG_SPLICE(kIROp_CombinedTextureSamplerGetSampler
1065
0
)
1066
0
SLANG_RAW(")\n")
1067
0
SLANG_RAW("    SamplerState __getSampler();\n")
1068
0
SLANG_RAW("\n")
1069
0
SLANG_RAW("    __intrinsic_op(")
1070
0
SLANG_SPLICE(kIROp_CombinedTextureSamplerGetSampler
1071
0
)
1072
0
SLANG_RAW(")\n")
1073
0
SLANG_RAW("    SamplerComparisonState __getComparisonSampler();\n")
1074
0
SLANG_RAW("\n")
1075
0
SLANG_RAW("    [__readNone]\n")
1076
0
SLANG_RAW("    [ForceInline]\n")
1077
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1078
0
SLANG_RAW("    float CalculateLevelOfDetail(TextureCoord location)\n")
1079
0
SLANG_RAW("    {\n")
1080
0
SLANG_RAW("        __requireComputeDerivative();\n")
1081
0
SLANG_RAW("        __target_switch\n")
1082
0
SLANG_RAW("        {\n")
1083
0
SLANG_RAW("        case hlsl:\n")
1084
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1085
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1086
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1087
0
SLANG_RAW("            return __getTexture().CalculateLevelOfDetail(__getSampler(), location);\n")
1088
0
SLANG_RAW("        case metal:\n")
1089
0
SLANG_RAW("            return __getTexture().CalculateLevelOfDetail(__getSampler(), location);\n")
1090
0
SLANG_RAW("        case glsl:\n")
1091
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($0, $1).x\";\n")
1092
0
SLANG_RAW("        case spirv:\n")
1093
0
SLANG_RAW("            return (spirv_asm\n")
1094
0
SLANG_RAW("            {\n")
1095
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1096
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod $this $location\n")
1097
0
SLANG_RAW("            }).x;\n")
1098
0
SLANG_RAW("        }\n")
1099
0
SLANG_RAW("    }\n")
1100
0
SLANG_RAW("\n")
1101
0
SLANG_RAW("    [__readNone]\n")
1102
0
SLANG_RAW("    [ForceInline]\n")
1103
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1104
0
SLANG_RAW("    float CalculateLevelOfDetailUnclamped(TextureCoord location)\n")
1105
0
SLANG_RAW("    {\n")
1106
0
SLANG_RAW("        __requireComputeDerivative();\n")
1107
0
SLANG_RAW("        __target_switch\n")
1108
0
SLANG_RAW("        {\n")
1109
0
SLANG_RAW("        case hlsl:\n")
1110
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1111
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1112
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1113
0
SLANG_RAW("            return __getTexture().CalculateLevelOfDetailUnclamped(__getSampler(), location);\n")
1114
0
SLANG_RAW("        case metal:\n")
1115
0
SLANG_RAW("            return __getTexture().CalculateLevelOfDetailUnclamped(__getSampler(), location);\n")
1116
0
SLANG_RAW("        case glsl:\n")
1117
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($0, $1).y\";\n")
1118
0
SLANG_RAW("        case spirv:\n")
1119
0
SLANG_RAW("            return (spirv_asm\n")
1120
0
SLANG_RAW("            {\n")
1121
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1122
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod $this $location\n")
1123
0
SLANG_RAW("            }).y;\n")
1124
0
SLANG_RAW("        }\n")
1125
0
SLANG_RAW("    }\n")
1126
0
SLANG_RAW("\n")
1127
0
SLANG_RAW("    /// Samples the texture at the given location.\n")
1128
0
SLANG_RAW("    ///\n")
1129
0
SLANG_RAW("    ///@param s The `SamplerState` to use for the sampling operation. This parameter is omitted when `this` is a combined texture sampler type (`isCombined == 0`).\n")
1130
0
SLANG_RAW("    ///@param location The location to sample the texture at.\n")
1131
0
SLANG_RAW("    ///@param offset Texel offset to apply.\n")
1132
0
SLANG_RAW("    ///@param clamp The max level of detail to use.\n")
1133
0
SLANG_RAW("    ///@param[out] status The result status of the operation.\n")
1134
0
SLANG_RAW("    ///                   This parameter is currently only used when targeting HLSL.\n")
1135
0
SLANG_RAW("    ///                   For other targets, the result status is always 0.\n")
1136
0
SLANG_RAW("    ///@return The sampled texture value.\n")
1137
0
SLANG_RAW("    ///@see `SampleBias`, `SampleLevel`, `SampleGrad`, `SampleCmp`, `SampleCmpLevelZero`, `SampleCmpLevel`.\n")
1138
0
SLANG_RAW("    ///@remarks\n")
1139
0
SLANG_RAW("    /// The `Sample` function is defined for all read-only texture types, including\n")
1140
0
SLANG_RAW("    /// `Texture1D`, `Texture2D`, `Texture3D`, `TextureCube`,\n")
1141
0
SLANG_RAW("    /// `Texture1DArray`, `Texture2DArray` and `TextureCubeArray`.\n")
1142
0
SLANG_RAW("    ///\n")
1143
0
SLANG_RAW("    /// The function is not available for read-write texture types.\n")
1144
0
SLANG_RAW("    ///\n")
1145
0
SLANG_RAW("    /// For HLSL/D3D targets, the texture element type must be a scalar or vector of float or half types.\n")
1146
0
SLANG_RAW("    ///\n")
1147
0
SLANG_RAW("    [__readNone]\n")
1148
0
SLANG_RAW("    [ForceInline]\n")
1149
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
1150
0
SLANG_RAW("    T Sample(vector<float, Shape.dimensions+isArray> location)\n")
1151
0
SLANG_RAW("    {\n")
1152
0
SLANG_RAW("        __requireComputeDerivative();\n")
1153
0
SLANG_RAW("        __target_switch\n")
1154
0
SLANG_RAW("        {\n")
1155
0
SLANG_RAW("            case hlsl:\n")
1156
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1157
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1158
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1159
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location);\n")
1160
0
SLANG_RAW("            case cpp:\n")
1161
0
SLANG_RAW("            case metal:\n")
1162
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location);\n")
1163
0
SLANG_RAW("            case glsl:\n")
1164
0
SLANG_RAW("                __intrinsic_asm \"$ctexture($0, $1)$z\";\n")
1165
0
SLANG_RAW("            case cuda:\n")
1166
0
SLANG_RAW("                if (isArray != 0)\n")
1167
0
SLANG_RAW("                {\n")
1168
0
SLANG_RAW("                    switch(Shape.flavor)\n")
1169
0
SLANG_RAW("                    {\n")
1170
0
SLANG_RAW("                    case ")
1171
0
SLANG_SPLICE(SLANG_TEXTURE_1D
1172
0
)
1173
0
SLANG_RAW(":\n")
1174
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLayered<$T0>($0, ($1).x, int(($1).y))\";\n")
1175
0
SLANG_RAW("                    case ")
1176
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1177
0
)
1178
0
SLANG_RAW(":\n")
1179
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLayered<$T0>($0, ($1).x, ($1).y, int(($1).z))\";\n")
1180
0
SLANG_RAW("                    case ")
1181
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1182
0
)
1183
0
SLANG_RAW(":\n")
1184
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLayered<$T0>($0, ($1).x, ($1).y, ($1).z, int(($1).w))\";\n")
1185
0
SLANG_RAW("                    default: __intrinsic_asm \"invalid texture shape\";\n")
1186
0
SLANG_RAW("                    }\n")
1187
0
SLANG_RAW("                }\n")
1188
0
SLANG_RAW("                else\n")
1189
0
SLANG_RAW("                {\n")
1190
0
SLANG_RAW("                    switch(Shape.flavor)\n")
1191
0
SLANG_RAW("                    {\n")
1192
0
SLANG_RAW("                    case ")
1193
0
SLANG_SPLICE(SLANG_TEXTURE_1D
1194
0
)
1195
0
SLANG_RAW(":\n")
1196
0
SLANG_RAW("                        __intrinsic_asm \"tex1D<$T0>($0, ($1))\";\n")
1197
0
SLANG_RAW("                    case ")
1198
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1199
0
)
1200
0
SLANG_RAW(":\n")
1201
0
SLANG_RAW("                        __intrinsic_asm \"tex2D<$T0>($0, ($1).x, ($1).y)\";\n")
1202
0
SLANG_RAW("                    case ")
1203
0
SLANG_SPLICE(SLANG_TEXTURE_3D
1204
0
)
1205
0
SLANG_RAW(":\n")
1206
0
SLANG_RAW("                        __intrinsic_asm \"tex3D<$T0>($0, ($1).x, ($1).y, ($1).z)\";\n")
1207
0
SLANG_RAW("                    case ")
1208
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1209
0
)
1210
0
SLANG_RAW(":\n")
1211
0
SLANG_RAW("                        __intrinsic_asm \"texCubemap<$T0>($0, ($1).x, ($1).y, ($1).z)\";\n")
1212
0
SLANG_RAW("                    default: __intrinsic_asm \"invalid texture shape\";\n")
1213
0
SLANG_RAW("                    }\n")
1214
0
SLANG_RAW("                }\n")
1215
0
SLANG_RAW("            case spirv:\n")
1216
0
SLANG_RAW("                return spirv_asm\n")
1217
0
SLANG_RAW("                {\n")
1218
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None;\n")
1219
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1220
0
SLANG_RAW("                };\n")
1221
0
SLANG_RAW("            case wgsl:\n")
1222
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location);\n")
1223
0
SLANG_RAW("        }\n")
1224
0
SLANG_RAW("    }\n")
1225
0
SLANG_RAW("\n")
1226
0
SLANG_RAW("    [__readNone]\n")
1227
0
SLANG_RAW("    [ForceInline]\n")
1228
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
1229
0
SLANG_RAW("    T Sample(vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset)\n")
1230
0
SLANG_RAW("    {\n")
1231
0
SLANG_RAW("        __requireComputeDerivative();\n")
1232
0
SLANG_RAW("        __target_switch\n")
1233
0
SLANG_RAW("        {\n")
1234
0
SLANG_RAW("            case hlsl:\n")
1235
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1236
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1237
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1238
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location, offset);\n")
1239
0
SLANG_RAW("            case cpp:\n")
1240
0
SLANG_RAW("            case metal:\n")
1241
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location, offset);\n")
1242
0
SLANG_RAW("            case glsl:\n")
1243
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffsetClampARB($0, $1, $2)$z\";\n")
1244
0
SLANG_RAW("            case spirv:\n")
1245
0
SLANG_RAW("                return spirv_asm\n")
1246
0
SLANG_RAW("                {\n")
1247
0
SLANG_RAW("                    OpCapability MinLod;\n")
1248
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None|ConstOffset $offset;\n")
1249
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1250
0
SLANG_RAW("                };\n")
1251
0
SLANG_RAW("            case wgsl:\n")
1252
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location, offset);\n")
1253
0
SLANG_RAW("        }\n")
1254
0
SLANG_RAW("    }\n")
1255
0
SLANG_RAW("\n")
1256
0
SLANG_RAW("    [__readNone]\n")
1257
0
SLANG_RAW("    [ForceInline]\n")
1258
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
1259
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv, texture_sm_4_1_clamp_fragment)]\n")
1260
0
SLANG_RAW("    T Sample(vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset, float clamp)\n")
1261
0
SLANG_RAW("    {\n")
1262
0
SLANG_RAW("        __requireComputeDerivative();\n")
1263
0
SLANG_RAW("        __target_switch\n")
1264
0
SLANG_RAW("        {\n")
1265
0
SLANG_RAW("            case hlsl:\n")
1266
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1267
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1268
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1269
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location, offset, clamp);\n")
1270
0
SLANG_RAW("            case cpp:\n")
1271
0
SLANG_RAW("            case metal:\n")
1272
0
SLANG_RAW("                return __getTexture().Sample(__getSampler(), location, offset, clamp);\n")
1273
0
SLANG_RAW("            case glsl:\n")
1274
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffsetClampARB($0, $1, $2, $3)$z\";\n")
1275
0
SLANG_RAW("            case spirv:\n")
1276
0
SLANG_RAW("                return spirv_asm\n")
1277
0
SLANG_RAW("                {\n")
1278
0
SLANG_RAW("                    OpCapability MinLod;\n")
1279
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None|ConstOffset|MinLod $offset $clamp;\n")
1280
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1281
0
SLANG_RAW("                };\n")
1282
0
SLANG_RAW("        }\n")
1283
0
SLANG_RAW("    }\n")
1284
0
SLANG_RAW("\n")
1285
0
SLANG_RAW("    [__readNone]\n")
1286
0
SLANG_RAW("    [ForceInline]\n")
1287
0
SLANG_RAW("    T Sample(vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
1288
0
SLANG_RAW("    {\n")
1289
0
SLANG_RAW("        __requireComputeDerivative();\n")
1290
0
SLANG_RAW("        __target_switch\n")
1291
0
SLANG_RAW("        {\n")
1292
0
SLANG_RAW("        case hlsl:\n")
1293
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1294
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1295
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1296
0
SLANG_RAW("            __intrinsic_asm \".Sample\";\n")
1297
0
SLANG_RAW("        case spirv:\n")
1298
0
SLANG_RAW("            return spirv_asm\n")
1299
0
SLANG_RAW("            {\n")
1300
0
SLANG_RAW("                OpCapability MinLod;\n")
1301
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1302
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
1303
0
SLANG_RAW("\n")
1304
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod $this $location ConstOffset|MinLod $offset $clamp;\n")
1305
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1306
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
1307
0
SLANG_RAW("\n")
1308
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1309
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
1310
0
SLANG_RAW("            };\n")
1311
0
SLANG_RAW("        default:\n")
1312
0
SLANG_RAW("            status = 0;\n")
1313
0
SLANG_RAW("            return Sample(location, offset, clamp);\n")
1314
0
SLANG_RAW("        }\n")
1315
0
SLANG_RAW("    }\n")
1316
0
SLANG_RAW("\n")
1317
0
SLANG_RAW("    [__readNone]\n")
1318
0
SLANG_RAW("    [ForceInline]\n")
1319
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
1320
0
SLANG_RAW("    T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias)\n")
1321
0
SLANG_RAW("    {\n")
1322
0
SLANG_RAW("        __requireComputeDerivative();\n")
1323
0
SLANG_RAW("        __target_switch\n")
1324
0
SLANG_RAW("        {\n")
1325
0
SLANG_RAW("            case hlsl:\n")
1326
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1327
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1328
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1329
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias);\n")
1330
0
SLANG_RAW("            case cpp:\n")
1331
0
SLANG_RAW("            case metal:\n")
1332
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias);\n")
1333
0
SLANG_RAW("            case glsl:\n")
1334
0
SLANG_RAW("                __intrinsic_asm \"$ctexture($0, $1, $2)$z\";\n")
1335
0
SLANG_RAW("            case spirv:\n")
1336
0
SLANG_RAW("                return spirv_asm\n")
1337
0
SLANG_RAW("                {\n")
1338
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None|Bias $bias;\n")
1339
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1340
0
SLANG_RAW("\n")
1341
0
SLANG_RAW("                };\n")
1342
0
SLANG_RAW("            case wgsl:\n")
1343
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias);\n")
1344
0
SLANG_RAW("        }\n")
1345
0
SLANG_RAW("    }\n")
1346
0
SLANG_RAW("\n")
1347
0
SLANG_RAW("    [__readNone]\n")
1348
0
SLANG_RAW("    [ForceInline]\n")
1349
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
1350
0
SLANG_RAW("    T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset)\n")
1351
0
SLANG_RAW("    {\n")
1352
0
SLANG_RAW("        __requireComputeDerivative();\n")
1353
0
SLANG_RAW("        __target_switch\n")
1354
0
SLANG_RAW("        {\n")
1355
0
SLANG_RAW("            case hlsl:\n")
1356
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1357
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1358
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1359
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias, offset);\n")
1360
0
SLANG_RAW("            case cpp:\n")
1361
0
SLANG_RAW("            case metal:\n")
1362
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias, offset);\n")
1363
0
SLANG_RAW("            case glsl:\n")
1364
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffset($0, $1, $3, $2)$z\";\n")
1365
0
SLANG_RAW("            case spirv:\n")
1366
0
SLANG_RAW("                return spirv_asm\n")
1367
0
SLANG_RAW("                {\n")
1368
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod $this $location None|Bias|ConstOffset $bias $offset;\n")
1369
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1370
0
SLANG_RAW("                };\n")
1371
0
SLANG_RAW("            case wgsl:\n")
1372
0
SLANG_RAW("                return __getTexture().SampleBias(__getSampler(), location, bias, offset);\n")
1373
0
SLANG_RAW("        }\n")
1374
0
SLANG_RAW("    }\n")
1375
0
SLANG_RAW("\n")
1376
0
SLANG_RAW("    [__readNone]\n")
1377
0
SLANG_RAW("    [ForceInline]\n")
1378
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
1379
0
SLANG_RAW("    T SampleBias(vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
1380
0
SLANG_RAW("    {\n")
1381
0
SLANG_RAW("        __requireComputeDerivative();\n")
1382
0
SLANG_RAW("        __target_switch\n")
1383
0
SLANG_RAW("        {\n")
1384
0
SLANG_RAW("        case hlsl:\n")
1385
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1386
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1387
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1388
0
SLANG_RAW("            return __getTexture().SampleBias(__getSampler(), location, bias, offset, clamp, status);\n")
1389
0
SLANG_RAW("        case spirv:\n")
1390
0
SLANG_RAW("            return spirv_asm\n")
1391
0
SLANG_RAW("            {\n")
1392
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1393
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
1394
0
SLANG_RAW("\n")
1395
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod $this $location Bias|ConstOffset $bias $offset;\n")
1396
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1397
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract  %sparseResult 1;\n")
1398
0
SLANG_RAW("\n")
1399
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1400
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
1401
0
SLANG_RAW("            };\n")
1402
0
SLANG_RAW("        }\n")
1403
0
SLANG_RAW("    }\n")
1404
0
SLANG_RAW("\n")
1405
0
SLANG_RAW("    [__readNone]\n")
1406
0
SLANG_RAW("    [ForceInline]\n")
1407
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
1408
0
SLANG_RAW("    float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue)\n")
1409
0
SLANG_RAW("    {\n")
1410
0
SLANG_RAW("        __requireComputeDerivative();\n")
1411
0
SLANG_RAW("        __target_switch\n")
1412
0
SLANG_RAW("        {\n")
1413
0
SLANG_RAW("        case glsl:\n")
1414
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
1415
0
SLANG_RAW("            {\n")
1416
0
SLANG_RAW("                return __glsl_texture_1d_shadow(this, __makeVector(__makeVector(location, 0.0), compareValue));\n")
1417
0
SLANG_RAW("            }\n")
1418
0
SLANG_RAW("            else if (Shape.dimensions == 3 && isArray == 1)\n")
1419
0
SLANG_RAW("            {\n")
1420
0
SLANG_RAW("                return __glsl_texture_3d_array_shadow(this, location, compareValue);\n")
1421
0
SLANG_RAW("            }\n")
1422
0
SLANG_RAW("            else\n")
1423
0
SLANG_RAW("            {\n")
1424
0
SLANG_RAW("                return __glsl_texture(this, __makeVector(location, compareValue));\n")
1425
0
SLANG_RAW("            }\n")
1426
0
SLANG_RAW("        case hlsl:\n")
1427
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1428
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1429
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1430
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue);\n")
1431
0
SLANG_RAW("        case metal:\n")
1432
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue);\n")
1433
0
SLANG_RAW("        case spirv:\n")
1434
0
SLANG_RAW("            return spirv_asm\n")
1435
0
SLANG_RAW("            {\n")
1436
0
SLANG_RAW("                result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue;\n")
1437
0
SLANG_RAW("            };\n")
1438
0
SLANG_RAW("        case wgsl:\n")
1439
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue);\n")
1440
0
SLANG_RAW("        }\n")
1441
0
SLANG_RAW("    }\n")
1442
0
SLANG_RAW("\n")
1443
0
SLANG_RAW("    [__readNone]\n")
1444
0
SLANG_RAW("    [ForceInline]\n")
1445
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
1446
0
SLANG_RAW("    float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue)\n")
1447
0
SLANG_RAW("    {\n")
1448
0
SLANG_RAW("        __target_switch\n")
1449
0
SLANG_RAW("        {\n")
1450
0
SLANG_RAW("        case hlsl:\n")
1451
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1452
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1453
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1454
0
SLANG_RAW("            return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);\n")
1455
0
SLANG_RAW("        case wgsl:\n")
1456
0
SLANG_RAW("            return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue);\n")
1457
0
SLANG_RAW("        default:\n")
1458
0
SLANG_RAW("            return SampleCmpLevel(location, compareValue, 0.0);\n")
1459
0
SLANG_RAW("        }\n")
1460
0
SLANG_RAW("    }\n")
1461
0
SLANG_RAW("\n")
1462
0
SLANG_RAW("    [__readNone]\n")
1463
0
SLANG_RAW("    [ForceInline]\n")
1464
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
1465
0
SLANG_RAW("    float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)\n")
1466
0
SLANG_RAW("    {\n")
1467
0
SLANG_RAW("        __requireComputeDerivative();\n")
1468
0
SLANG_RAW("        __target_switch\n")
1469
0
SLANG_RAW("        {\n")
1470
0
SLANG_RAW("        case glsl:\n")
1471
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
1472
0
SLANG_RAW("            {\n")
1473
0
SLANG_RAW("                return __glsl_texture_offset_1d_shadow(this, __makeVector(__makeVector(location, 0.0), compareValue), offset);\n")
1474
0
SLANG_RAW("            }\n")
1475
0
SLANG_RAW("            else\n")
1476
0
SLANG_RAW("            {\n")
1477
0
SLANG_RAW("                return __glsl_texture_offset(this, __makeVector(location, compareValue), offset);\n")
1478
0
SLANG_RAW("            }\n")
1479
0
SLANG_RAW("        case hlsl:\n")
1480
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1481
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1482
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1483
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset);\n")
1484
0
SLANG_RAW("        case metal:\n")
1485
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset);\n")
1486
0
SLANG_RAW("        case spirv:\n")
1487
0
SLANG_RAW("            return spirv_asm\n")
1488
0
SLANG_RAW("            {\n")
1489
0
SLANG_RAW("                result:$$float = OpImageSampleDrefImplicitLod $this $location $compareValue ConstOffset $offset;\n")
1490
0
SLANG_RAW("            };\n")
1491
0
SLANG_RAW("        case wgsl:\n")
1492
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset);\n")
1493
0
SLANG_RAW("        }\n")
1494
0
SLANG_RAW("    }\n")
1495
0
SLANG_RAW("\n")
1496
0
SLANG_RAW("\n")
1497
0
SLANG_RAW("    [__readNone]\n")
1498
0
SLANG_RAW("    [ForceInline]\n")
1499
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
1500
0
SLANG_RAW("    float SampleCmp(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
1501
0
SLANG_RAW("    {\n")
1502
0
SLANG_RAW("        __requireComputeDerivative();\n")
1503
0
SLANG_RAW("        __target_switch\n")
1504
0
SLANG_RAW("        {\n")
1505
0
SLANG_RAW("        case hlsl:\n")
1506
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1507
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1508
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1509
0
SLANG_RAW("            return __getTexture().SampleCmp(__getComparisonSampler(), location, compareValue, offset, clamp, status);\n")
1510
0
SLANG_RAW("        case spirv:\n")
1511
0
SLANG_RAW("            return spirv_asm\n")
1512
0
SLANG_RAW("            {\n")
1513
0
SLANG_RAW("                OpCapability MinLod;\n")
1514
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1515
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint $$float;\n")
1516
0
SLANG_RAW("\n")
1517
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod $this $location $compareValue ConstOffset|MinLod $offset $clamp;\n")
1518
0
SLANG_RAW("\n")
1519
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1520
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1521
0
SLANG_RAW("                result:$$float = OpCompositeExtract %sparseResult 1;\n")
1522
0
SLANG_RAW("            };\n")
1523
0
SLANG_RAW("        }\n")
1524
0
SLANG_RAW("    }\n")
1525
0
SLANG_RAW("\n")
1526
0
SLANG_RAW("    [__readNone]\n")
1527
0
SLANG_RAW("    [ForceInline]\n")
1528
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
1529
0
SLANG_RAW("    float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)\n")
1530
0
SLANG_RAW("    {\n")
1531
0
SLANG_RAW("        __target_switch\n")
1532
0
SLANG_RAW("        {\n")
1533
0
SLANG_RAW("        case hlsl:\n")
1534
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1535
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1536
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1537
0
SLANG_RAW("            return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);\n")
1538
0
SLANG_RAW("        case wgsl:\n")
1539
0
SLANG_RAW("            return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset);\n")
1540
0
SLANG_RAW("        default:\n")
1541
0
SLANG_RAW("            return SampleCmpLevel(location, compareValue, 0.0, offset);\n")
1542
0
SLANG_RAW("        }\n")
1543
0
SLANG_RAW("    }\n")
1544
0
SLANG_RAW("\n")
1545
0
SLANG_RAW("    [__readNone]\n")
1546
0
SLANG_RAW("    [ForceInline]\n")
1547
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
1548
0
SLANG_RAW("    float SampleCmpLevelZero(vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
1549
0
SLANG_RAW("    {\n")
1550
0
SLANG_RAW("        __target_switch\n")
1551
0
SLANG_RAW("        {\n")
1552
0
SLANG_RAW("        case hlsl:\n")
1553
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1554
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1555
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1556
0
SLANG_RAW("            return __getTexture().SampleCmpLevelZero(__getComparisonSampler(), location, compareValue, offset, status);\n")
1557
0
SLANG_RAW("        case spirv:\n")
1558
0
SLANG_RAW("            return SampleCmpLevel(location, compareValue, 0.0, offset, status);\n")
1559
0
SLANG_RAW("        }\n")
1560
0
SLANG_RAW("    }\n")
1561
0
SLANG_RAW("\n")
1562
0
SLANG_RAW("    [__readNone]\n")
1563
0
SLANG_RAW("    [ForceInline]\n")
1564
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_shadowlod)]\n")
1565
0
SLANG_RAW("    float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level)\n")
1566
0
SLANG_RAW("    {\n")
1567
0
SLANG_RAW("        __target_switch\n")
1568
0
SLANG_RAW("        {\n")
1569
0
SLANG_RAW("        case glsl:\n")
1570
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
1571
0
SLANG_RAW("            {\n")
1572
0
SLANG_RAW("                return __glsl_texture_level_1d_shadow(this, __makeVector(__makeVector(location, 0.0), compareValue), level);\n")
1573
0
SLANG_RAW("            }\n")
1574
0
SLANG_RAW("            else\n")
1575
0
SLANG_RAW("            {\n")
1576
0
SLANG_RAW("                return __glsl_texture_level(this, __makeVector(location, compareValue), level);\n")
1577
0
SLANG_RAW("            }\n")
1578
0
SLANG_RAW("        case hlsl:\n")
1579
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1580
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1581
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1582
0
SLANG_RAW("            return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level);\n")
1583
0
SLANG_RAW("        case metal:\n")
1584
0
SLANG_RAW("            return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level);\n")
1585
0
SLANG_RAW("        case spirv:\n")
1586
0
SLANG_RAW("            return spirv_asm\n")
1587
0
SLANG_RAW("            {\n")
1588
0
SLANG_RAW("                result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod $level;\n")
1589
0
SLANG_RAW("            };\n")
1590
0
SLANG_RAW("        }\n")
1591
0
SLANG_RAW("    }\n")
1592
0
SLANG_RAW("\n")
1593
0
SLANG_RAW("    [__readNone]\n")
1594
0
SLANG_RAW("    [ForceInline]\n")
1595
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_shadowlod)]\n")
1596
0
SLANG_RAW("    float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset)\n")
1597
0
SLANG_RAW("    {\n")
1598
0
SLANG_RAW("        __target_switch\n")
1599
0
SLANG_RAW("        {\n")
1600
0
SLANG_RAW("        case glsl:\n")
1601
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
1602
0
SLANG_RAW("            {\n")
1603
0
SLANG_RAW("                return __glsl_texture_level_offset_1d_shadow(this, __makeVector(__makeVector(location,0.0), compareValue), level, offset);\n")
1604
0
SLANG_RAW("            }\n")
1605
0
SLANG_RAW("            else\n")
1606
0
SLANG_RAW("            {\n")
1607
0
SLANG_RAW("                return __glsl_texture_level_offset(this, __makeVector(location, compareValue), level, offset);\n")
1608
0
SLANG_RAW("            }\n")
1609
0
SLANG_RAW("        case hlsl:\n")
1610
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1611
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1612
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1613
0
SLANG_RAW("            return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset);\n")
1614
0
SLANG_RAW("        case metal:\n")
1615
0
SLANG_RAW("            return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset);\n")
1616
0
SLANG_RAW("        case spirv:\n")
1617
0
SLANG_RAW("            return spirv_asm\n")
1618
0
SLANG_RAW("            {\n")
1619
0
SLANG_RAW("                result:$$float = OpImageSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $level $offset;\n")
1620
0
SLANG_RAW("            };\n")
1621
0
SLANG_RAW("        }\n")
1622
0
SLANG_RAW("    }\n")
1623
0
SLANG_RAW("\n")
1624
0
SLANG_RAW("    [__readNone]\n")
1625
0
SLANG_RAW("    [ForceInline]\n")
1626
0
SLANG_RAW("    [require(hlsl_spirv, texture_shadowlod)]\n")
1627
0
SLANG_RAW("    float SampleCmpLevel(vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
1628
0
SLANG_RAW("    {\n")
1629
0
SLANG_RAW("        __target_switch\n")
1630
0
SLANG_RAW("        {\n")
1631
0
SLANG_RAW("        case hlsl:\n")
1632
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1633
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1634
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1635
0
SLANG_RAW("            return __getTexture().SampleCmpLevel(__getComparisonSampler(), location, compareValue, level, offset, status);\n")
1636
0
SLANG_RAW("        case spirv:\n")
1637
0
SLANG_RAW("            return spirv_asm\n")
1638
0
SLANG_RAW("            {\n")
1639
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1640
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint $$float;\n")
1641
0
SLANG_RAW("\n")
1642
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod $this $location $compareValue Lod|ConstOffset $level $offset;\n")
1643
0
SLANG_RAW("\n")
1644
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1645
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1646
0
SLANG_RAW("                result:$$float = OpCompositeExtract %sparseResult 1;\n")
1647
0
SLANG_RAW("            };\n")
1648
0
SLANG_RAW("        }\n")
1649
0
SLANG_RAW("    }\n")
1650
0
SLANG_RAW("\n")
1651
0
SLANG_RAW("    [__readNone]\n")
1652
0
SLANG_RAW("    [ForceInline]\n")
1653
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
1654
0
SLANG_RAW("    T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)\n")
1655
0
SLANG_RAW("    {\n")
1656
0
SLANG_RAW("        __target_switch\n")
1657
0
SLANG_RAW("        {\n")
1658
0
SLANG_RAW("            case hlsl:\n")
1659
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1660
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1661
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1662
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY);\n")
1663
0
SLANG_RAW("            case cpp:\n")
1664
0
SLANG_RAW("            case metal:\n")
1665
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY);\n")
1666
0
SLANG_RAW("            case glsl:\n")
1667
0
SLANG_RAW("                __intrinsic_asm \"$ctextureGrad($0, $1, $2, $3)$z\";\n")
1668
0
SLANG_RAW("            case spirv:\n")
1669
0
SLANG_RAW("                return spirv_asm\n")
1670
0
SLANG_RAW("                {\n")
1671
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Grad $gradX $gradY;\n")
1672
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1673
0
SLANG_RAW("                };\n")
1674
0
SLANG_RAW("            case wgsl:\n")
1675
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY);\n")
1676
0
SLANG_RAW("        }\n")
1677
0
SLANG_RAW("    }\n")
1678
0
SLANG_RAW("\n")
1679
0
SLANG_RAW("    [__readNone]\n")
1680
0
SLANG_RAW("    [ForceInline]\n")
1681
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
1682
0
SLANG_RAW("    T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset)\n")
1683
0
SLANG_RAW("    {\n")
1684
0
SLANG_RAW("        __target_switch\n")
1685
0
SLANG_RAW("        {\n")
1686
0
SLANG_RAW("            case hlsl:\n")
1687
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1688
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1689
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1690
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset);\n")
1691
0
SLANG_RAW("            case cpp:\n")
1692
0
SLANG_RAW("            case metal:\n")
1693
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset);\n")
1694
0
SLANG_RAW("            case glsl:\n")
1695
0
SLANG_RAW("                __intrinsic_asm \"$ctextureGradOffset($0, $1, $2, $3, $4)$z\";\n")
1696
0
SLANG_RAW("            case spirv:\n")
1697
0
SLANG_RAW("                return spirv_asm\n")
1698
0
SLANG_RAW("                {\n")
1699
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Grad|ConstOffset $gradX $gradY $offset;\n")
1700
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1701
0
SLANG_RAW("                };\n")
1702
0
SLANG_RAW("            case wgsl:\n")
1703
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset);\n")
1704
0
SLANG_RAW("        }\n")
1705
0
SLANG_RAW("    }\n")
1706
0
SLANG_RAW("\n")
1707
0
SLANG_RAW("    [__readNone]\n")
1708
0
SLANG_RAW("    [ForceInline]\n")
1709
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
1710
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv, texture_sm_4_1_clamp_fragment)]\n")
1711
0
SLANG_RAW("    T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp)\n")
1712
0
SLANG_RAW("    {\n")
1713
0
SLANG_RAW("        __target_switch\n")
1714
0
SLANG_RAW("        {\n")
1715
0
SLANG_RAW("            case hlsl:\n")
1716
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1717
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1718
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1719
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp);\n")
1720
0
SLANG_RAW("            case cpp:\n")
1721
0
SLANG_RAW("            case metal:\n")
1722
0
SLANG_RAW("                return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp);\n")
1723
0
SLANG_RAW("            case glsl:\n")
1724
0
SLANG_RAW("            __intrinsic_asm \"$ctextureGradOffsetClampARB($0, $1, $2, $3, $4, $5)$z\";\n")
1725
0
SLANG_RAW("            case spirv:\n")
1726
0
SLANG_RAW("                return spirv_asm\n")
1727
0
SLANG_RAW("                {\n")
1728
0
SLANG_RAW("                    OpCapability MinLod;\n")
1729
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp;\n")
1730
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1731
0
SLANG_RAW("                };\n")
1732
0
SLANG_RAW("        }\n")
1733
0
SLANG_RAW("    }\n")
1734
0
SLANG_RAW("\n")
1735
0
SLANG_RAW("    [__readNone]\n")
1736
0
SLANG_RAW("    [ForceInline]\n")
1737
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
1738
0
SLANG_RAW("    T SampleGrad(vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp, out uint status)\n")
1739
0
SLANG_RAW("    {\n")
1740
0
SLANG_RAW("        __target_switch\n")
1741
0
SLANG_RAW("        {\n")
1742
0
SLANG_RAW("        case hlsl:\n")
1743
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1744
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1745
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1746
0
SLANG_RAW("            return __getTexture().SampleGrad(__getSampler(), location, gradX, gradY, offset, lodClamp, status);\n")
1747
0
SLANG_RAW("        case spirv:\n")
1748
0
SLANG_RAW("            return spirv_asm\n")
1749
0
SLANG_RAW("            {\n")
1750
0
SLANG_RAW("                OpCapability MinLod;\n")
1751
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1752
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
1753
0
SLANG_RAW("\n")
1754
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod $this $location Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp;\n")
1755
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1756
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
1757
0
SLANG_RAW("\n")
1758
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1759
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
1760
0
SLANG_RAW("            };\n")
1761
0
SLANG_RAW("        }\n")
1762
0
SLANG_RAW("    }\n")
1763
0
SLANG_RAW("\n")
1764
0
SLANG_RAW("    [__readNone]\n")
1765
0
SLANG_RAW("    [ForceInline]\n")
1766
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
1767
0
SLANG_RAW("    T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level)\n")
1768
0
SLANG_RAW("    {\n")
1769
0
SLANG_RAW("        __target_switch\n")
1770
0
SLANG_RAW("        {\n")
1771
0
SLANG_RAW("            case hlsl:\n")
1772
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1773
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1774
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1775
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level);\n")
1776
0
SLANG_RAW("            case cpp:\n")
1777
0
SLANG_RAW("            case metal:\n")
1778
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level);\n")
1779
0
SLANG_RAW("            case glsl:\n")
1780
0
SLANG_RAW("                __intrinsic_asm \"$ctextureLod($0, $1, $2)$z\";\n")
1781
0
SLANG_RAW("            case cuda:\n")
1782
0
SLANG_RAW("                if (isArray != 0)\n")
1783
0
SLANG_RAW("                {\n")
1784
0
SLANG_RAW("                    switch(Shape.flavor)\n")
1785
0
SLANG_RAW("                    {\n")
1786
0
SLANG_RAW("                    case ")
1787
0
SLANG_SPLICE(SLANG_TEXTURE_1D
1788
0
)
1789
0
SLANG_RAW(":\n")
1790
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLayeredLod<$T0>($0, ($1).x, int(($1).y), ($2))\";\n")
1791
0
SLANG_RAW("                    case ")
1792
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1793
0
)
1794
0
SLANG_RAW(":\n")
1795
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLayeredLod<$T0>($0, ($1).x, ($1).y, int(($1).z), ($2))\";\n")
1796
0
SLANG_RAW("                    case ")
1797
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1798
0
)
1799
0
SLANG_RAW(":\n")
1800
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLayeredLod<$T0>($0, ($1).x, ($1).y, ($1).z, int(($1).w), ($2))\";\n")
1801
0
SLANG_RAW("                    default:\n")
1802
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
1803
0
SLANG_RAW("                    }\n")
1804
0
SLANG_RAW("                }\n")
1805
0
SLANG_RAW("                else\n")
1806
0
SLANG_RAW("                {\n")
1807
0
SLANG_RAW("                    switch(Shape.flavor)\n")
1808
0
SLANG_RAW("                    {\n")
1809
0
SLANG_RAW("                    case ")
1810
0
SLANG_SPLICE(SLANG_TEXTURE_1D
1811
0
)
1812
0
SLANG_RAW(":\n")
1813
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLod<$T0>($0, ($1), ($2))\";\n")
1814
0
SLANG_RAW("                    case ")
1815
0
SLANG_SPLICE(SLANG_TEXTURE_2D
1816
0
)
1817
0
SLANG_RAW(":\n")
1818
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLod<$T0>($0, ($1).x, ($1).y, ($2))\";\n")
1819
0
SLANG_RAW("                    case ")
1820
0
SLANG_SPLICE(SLANG_TEXTURE_3D
1821
0
)
1822
0
SLANG_RAW(":\n")
1823
0
SLANG_RAW("                        __intrinsic_asm \"tex3DLod<$T0>($0, ($1).x, ($1).y, ($1).z, ($2))\";\n")
1824
0
SLANG_RAW("                    case ")
1825
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
1826
0
)
1827
0
SLANG_RAW(":\n")
1828
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLod<$T0>($0, ($1).x, ($1).y, ($1).z, ($2))\";\n")
1829
0
SLANG_RAW("                    default:\n")
1830
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
1831
0
SLANG_RAW("                    }\n")
1832
0
SLANG_RAW("                }\n")
1833
0
SLANG_RAW("            case spirv:\n")
1834
0
SLANG_RAW("                return spirv_asm\n")
1835
0
SLANG_RAW("                {\n")
1836
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Lod $level;\n")
1837
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1838
0
SLANG_RAW("                };\n")
1839
0
SLANG_RAW("            case wgsl:\n")
1840
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level);\n")
1841
0
SLANG_RAW("        }\n")
1842
0
SLANG_RAW("    }\n")
1843
0
SLANG_RAW("\n")
1844
0
SLANG_RAW("    [__readNone]\n")
1845
0
SLANG_RAW("    [ForceInline]\n")
1846
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
1847
0
SLANG_RAW("    T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset)\n")
1848
0
SLANG_RAW("    {\n")
1849
0
SLANG_RAW("        __target_switch\n")
1850
0
SLANG_RAW("        {\n")
1851
0
SLANG_RAW("            case hlsl:\n")
1852
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1853
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1854
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
1855
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level, offset);\n")
1856
0
SLANG_RAW("            case cpp:\n")
1857
0
SLANG_RAW("            case metal:\n")
1858
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level, offset);\n")
1859
0
SLANG_RAW("            case glsl:\n")
1860
0
SLANG_RAW("                __intrinsic_asm \"$ctextureLodOffset($0, $1, $2, $3)$z\";\n")
1861
0
SLANG_RAW("            case spirv:\n")
1862
0
SLANG_RAW("                return spirv_asm\n")
1863
0
SLANG_RAW("                {\n")
1864
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod $this $location None|Lod|ConstOffset $level $offset;\n")
1865
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
1866
0
SLANG_RAW("                };\n")
1867
0
SLANG_RAW("            case wgsl:\n")
1868
0
SLANG_RAW("                return __getTexture().SampleLevel(__getSampler(), location, level, offset);\n")
1869
0
SLANG_RAW("        }\n")
1870
0
SLANG_RAW("    }\n")
1871
0
SLANG_RAW("\n")
1872
0
SLANG_RAW("    [__readNone]\n")
1873
0
SLANG_RAW("    [ForceInline]\n")
1874
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
1875
0
SLANG_RAW("    T SampleLevel(vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
1876
0
SLANG_RAW("    {\n")
1877
0
SLANG_RAW("        __target_switch\n")
1878
0
SLANG_RAW("        {\n")
1879
0
SLANG_RAW("        case hlsl:\n")
1880
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
1881
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
1882
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
1883
0
SLANG_RAW("            return __getTexture().SampleLevel(__getSampler(), location, level, offset, status);\n")
1884
0
SLANG_RAW("        case spirv:\n")
1885
0
SLANG_RAW("            return spirv_asm\n")
1886
0
SLANG_RAW("            {\n")
1887
0
SLANG_RAW("                OpCapability SparseResidency;\n")
1888
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
1889
0
SLANG_RAW("\n")
1890
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod $this $location Lod|ConstOffset $level $offset;\n")
1891
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
1892
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
1893
0
SLANG_RAW("\n")
1894
0
SLANG_RAW("                OpStore &status %residentCode;\n")
1895
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
1896
0
SLANG_RAW("            };\n")
1897
0
SLANG_RAW("        }\n")
1898
0
SLANG_RAW("    }\n")
1899
0
SLANG_RAW("}\n")
1900
0
SLANG_RAW("\n")
1901
0
SLANG_RAW("// Non-combined texture types specific functions\n")
1902
0
SLANG_RAW("\n")
1903
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
1904
0
SLANG_RAW("extension _Texture<T,Shape,isArray,isMS,sampleCount,access,isShadow,0,format>\n")
1905
0
SLANG_RAW("{\n")
1906
0
SLANG_RAW("    typealias TextureCoord = vector<float, Shape.dimensions>;\n")
1907
0
SLANG_RAW("\n")
1908
0
SLANG_RAW("    [__readNone]\n")
1909
0
SLANG_RAW("    [ForceInline]\n")
1910
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1911
0
SLANG_RAW("    float CalculateLevelOfDetail(SamplerState s, TextureCoord location)\n")
1912
0
SLANG_RAW("    {\n")
1913
0
SLANG_RAW("        __requireComputeDerivative();\n")
1914
0
SLANG_RAW("        __target_switch\n")
1915
0
SLANG_RAW("        {\n")
1916
0
SLANG_RAW("        case hlsl:\n")
1917
0
SLANG_RAW("            __intrinsic_asm \".CalculateLevelOfDetail\";\n")
1918
0
SLANG_RAW("        case metal:\n")
1919
0
SLANG_RAW("            __intrinsic_asm \".calculate_clamped_lod\";\n")
1920
0
SLANG_RAW("        case glsl:\n")
1921
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($p, $2).x\";\n")
1922
0
SLANG_RAW("        case spirv:\n")
1923
0
SLANG_RAW("            return (spirv_asm {\n")
1924
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1925
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
1926
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod %sampledImage $location;\n")
1927
0
SLANG_RAW("            }).x;\n")
1928
0
SLANG_RAW("        }\n")
1929
0
SLANG_RAW("    }\n")
1930
0
SLANG_RAW("\n")
1931
0
SLANG_RAW("    [__readNone]\n")
1932
0
SLANG_RAW("    [ForceInline]\n")
1933
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1934
0
SLANG_RAW("    float CalculateLevelOfDetailUnclamped(SamplerState s, TextureCoord location)\n")
1935
0
SLANG_RAW("    {\n")
1936
0
SLANG_RAW("        __requireComputeDerivative();\n")
1937
0
SLANG_RAW("        __target_switch\n")
1938
0
SLANG_RAW("        {\n")
1939
0
SLANG_RAW("        case hlsl:\n")
1940
0
SLANG_RAW("            __intrinsic_asm \".CalculateLevelOfDetailUnclamped\";\n")
1941
0
SLANG_RAW("        case metal:\n")
1942
0
SLANG_RAW("            __intrinsic_asm \".calculate_unclamped_lod\";\n")
1943
0
SLANG_RAW("        case glsl:\n")
1944
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($p, $2).y\";\n")
1945
0
SLANG_RAW("        case spirv:\n")
1946
0
SLANG_RAW("            return (spirv_asm {\n")
1947
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1948
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
1949
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod %sampledImage $location;\n")
1950
0
SLANG_RAW("            }).y;\n")
1951
0
SLANG_RAW("        }\n")
1952
0
SLANG_RAW("    }\n")
1953
0
SLANG_RAW("\n")
1954
0
SLANG_RAW("    [__readNone]\n")
1955
0
SLANG_RAW("    [ForceInline]\n")
1956
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1957
0
SLANG_RAW("    float CalculateLevelOfDetail(SamplerComparisonState s, TextureCoord location)\n")
1958
0
SLANG_RAW("    {\n")
1959
0
SLANG_RAW("        __requireComputeDerivative();\n")
1960
0
SLANG_RAW("        __target_switch\n")
1961
0
SLANG_RAW("        {\n")
1962
0
SLANG_RAW("        case hlsl:\n")
1963
0
SLANG_RAW("            __intrinsic_asm \".CalculateLevelOfDetail\";\n")
1964
0
SLANG_RAW("        case metal:\n")
1965
0
SLANG_RAW("            __intrinsic_asm \".calculate_clamped_lod\";\n")
1966
0
SLANG_RAW("        case glsl:\n")
1967
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($p, $2).x\";\n")
1968
0
SLANG_RAW("        case spirv:\n")
1969
0
SLANG_RAW("            return (spirv_asm {\n")
1970
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1971
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
1972
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod %sampledImage $location;\n")
1973
0
SLANG_RAW("            }).x;\n")
1974
0
SLANG_RAW("        }\n")
1975
0
SLANG_RAW("    }\n")
1976
0
SLANG_RAW("\n")
1977
0
SLANG_RAW("    [__readNone]\n")
1978
0
SLANG_RAW("    [ForceInline]\n")
1979
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_querylod)]\n")
1980
0
SLANG_RAW("    float CalculateLevelOfDetailUnclamped(SamplerComparisonState s, TextureCoord location)\n")
1981
0
SLANG_RAW("    {\n")
1982
0
SLANG_RAW("        __requireComputeDerivative();\n")
1983
0
SLANG_RAW("        __target_switch\n")
1984
0
SLANG_RAW("        {\n")
1985
0
SLANG_RAW("        case hlsl:\n")
1986
0
SLANG_RAW("            __intrinsic_asm \".CalculateLevelOfDetailUnclamped\";\n")
1987
0
SLANG_RAW("        case metal:\n")
1988
0
SLANG_RAW("            __intrinsic_asm \".calculate_unclamped_lod\";\n")
1989
0
SLANG_RAW("        case glsl:\n")
1990
0
SLANG_RAW("            __intrinsic_asm \"textureQueryLod($p, $2).y\";\n")
1991
0
SLANG_RAW("        case spirv:\n")
1992
0
SLANG_RAW("            return (spirv_asm {\n")
1993
0
SLANG_RAW("                OpCapability ImageQuery;\n")
1994
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
1995
0
SLANG_RAW("                result:$$float2 = OpImageQueryLod %sampledImage $location;\n")
1996
0
SLANG_RAW("            }).y;\n")
1997
0
SLANG_RAW("        }\n")
1998
0
SLANG_RAW("    }\n")
1999
0
SLANG_RAW("}\n")
2000
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let format:int>\n")
2001
0
SLANG_RAW("float __metal_SampleCmp(_Texture<T,Shape,isArray,isMS,sampleCount,0,1,0,format> t, SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue)\n")
2002
0
SLANG_RAW("{\n")
2003
0
SLANG_RAW("    if (isArray == 1)\n")
2004
0
SLANG_RAW("    {\n")
2005
0
SLANG_RAW("        switch (Shape.flavor)\n")
2006
0
SLANG_RAW("        {\n")
2007
0
SLANG_RAW("        case ")
2008
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2009
0
)
2010
0
SLANG_RAW(":\n")
2011
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xy, uint(($2).z), $3)\";\n")
2012
0
SLANG_RAW("        case ")
2013
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2014
0
)
2015
0
SLANG_RAW(":\n")
2016
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xyz, uint(($2).w), $3)\";\n")
2017
0
SLANG_RAW("        }\n")
2018
0
SLANG_RAW("    }\n")
2019
0
SLANG_RAW("    else\n")
2020
0
SLANG_RAW("    {\n")
2021
0
SLANG_RAW("        switch (Shape.flavor)\n")
2022
0
SLANG_RAW("        {\n")
2023
0
SLANG_RAW("        case ")
2024
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2025
0
)
2026
0
SLANG_RAW(":\n")
2027
0
SLANG_RAW("        case ")
2028
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2029
0
)
2030
0
SLANG_RAW(":\n")
2031
0
SLANG_RAW("            __intrinsic_asm \".sample_compare\";\n")
2032
0
SLANG_RAW("        }\n")
2033
0
SLANG_RAW("    }\n")
2034
0
SLANG_RAW("    __intrinsic_asm \"<invalid intrinsic>\";\n")
2035
0
SLANG_RAW("}\n")
2036
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let format:int>\n")
2037
0
SLANG_RAW("float __metal_SampleCmp(_Texture<T,Shape,isArray,isMS,sampleCount,0,1,0,format> t, SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)\n")
2038
0
SLANG_RAW("{\n")
2039
0
SLANG_RAW("    if (isArray == 1)\n")
2040
0
SLANG_RAW("    {\n")
2041
0
SLANG_RAW("        switch (Shape.flavor)\n")
2042
0
SLANG_RAW("        {\n")
2043
0
SLANG_RAW("        case ")
2044
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2045
0
)
2046
0
SLANG_RAW(":\n")
2047
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xy, uint(($2).z), $3, $4)\";\n")
2048
0
SLANG_RAW("        }\n")
2049
0
SLANG_RAW("    }\n")
2050
0
SLANG_RAW("    else\n")
2051
0
SLANG_RAW("    {\n")
2052
0
SLANG_RAW("        switch (Shape.flavor)\n")
2053
0
SLANG_RAW("        {\n")
2054
0
SLANG_RAW("        case ")
2055
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2056
0
)
2057
0
SLANG_RAW(":\n")
2058
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, $2, $3, $4)\";\n")
2059
0
SLANG_RAW("        }\n")
2060
0
SLANG_RAW("    }\n")
2061
0
SLANG_RAW("    __intrinsic_asm \"<invalid intrinsic>\";\n")
2062
0
SLANG_RAW("}\n")
2063
0
SLANG_RAW("\n")
2064
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let format:int>\n")
2065
0
SLANG_RAW("float __metal_SampleCmpLevel(_Texture<T,Shape,isArray,isMS,sampleCount,0,1,0,format> t, SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level)\n")
2066
0
SLANG_RAW("{\n")
2067
0
SLANG_RAW("    if (isArray == 1)\n")
2068
0
SLANG_RAW("    {\n")
2069
0
SLANG_RAW("        switch (Shape.flavor)\n")
2070
0
SLANG_RAW("        {\n")
2071
0
SLANG_RAW("        case ")
2072
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2073
0
)
2074
0
SLANG_RAW(":\n")
2075
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level($4))\";\n")
2076
0
SLANG_RAW("        case ")
2077
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2078
0
)
2079
0
SLANG_RAW(":\n")
2080
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xyz, uint(($2).w), $3, level($4))\";\n")
2081
0
SLANG_RAW("        }\n")
2082
0
SLANG_RAW("    }\n")
2083
0
SLANG_RAW("    else\n")
2084
0
SLANG_RAW("    {\n")
2085
0
SLANG_RAW("        switch (Shape.flavor)\n")
2086
0
SLANG_RAW("        {\n")
2087
0
SLANG_RAW("        case ")
2088
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2089
0
)
2090
0
SLANG_RAW(":\n")
2091
0
SLANG_RAW("        case ")
2092
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2093
0
)
2094
0
SLANG_RAW(":\n")
2095
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, $2, $3, level($4))\";\n")
2096
0
SLANG_RAW("        }\n")
2097
0
SLANG_RAW("    }\n")
2098
0
SLANG_RAW("    __intrinsic_asm \"<invalid intrinsic>\";\n")
2099
0
SLANG_RAW("}\n")
2100
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let format:int>\n")
2101
0
SLANG_RAW("float __metal_SampleCmpLevel(_Texture<T,Shape,isArray,isMS,sampleCount,0,1,0,format> t, SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset)\n")
2102
0
SLANG_RAW("{\n")
2103
0
SLANG_RAW("    switch (Shape.flavor)\n")
2104
0
SLANG_RAW("    {\n")
2105
0
SLANG_RAW("    case ")
2106
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2107
0
)
2108
0
SLANG_RAW(":\n")
2109
0
SLANG_RAW("        if (isArray == 1)\n")
2110
0
SLANG_RAW("        {\n")
2111
0
SLANG_RAW("            // T sample_compare(sampler s, float2 coord, uint array, float compare_value, lod_options options, int2 offset = int2(0)) const\n")
2112
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, ($2).xy, uint(($2).z), $3, level($4), $5)\";\n")
2113
0
SLANG_RAW("        }\n")
2114
0
SLANG_RAW("        else\n")
2115
0
SLANG_RAW("        {\n")
2116
0
SLANG_RAW("            // T sample_compare(sampler s, float2 coord, float compare_value, lod_options options, int2 offset = int2(0)) const\n")
2117
0
SLANG_RAW("            __intrinsic_asm \"$0.sample_compare($1, $2, $3, level($4), $5)\";\n")
2118
0
SLANG_RAW("        }\n")
2119
0
SLANG_RAW("        break;\n")
2120
0
SLANG_RAW("    }\n")
2121
0
SLANG_RAW("    __intrinsic_asm \"<invalid intrinsic>\";\n")
2122
0
SLANG_RAW("}\n")
2123
0
SLANG_RAW("\n")
2124
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let isShadow:int, let format:int>\n")
2125
0
SLANG_RAW("extension _Texture<T,Shape,isArray,isMS,sampleCount,0,isShadow,0,format>\n")
2126
0
SLANG_RAW("{\n")
2127
0
SLANG_RAW("    //@hidden:\n")
2128
0
SLANG_RAW("    static const int access = 0;\n")
2129
0
SLANG_RAW("    static const int isCombined = 0;\n")
2130
0
SLANG_RAW("\n")
2131
0
SLANG_RAW("    //@public:\n")
2132
0
SLANG_RAW("    [__readNone]\n")
2133
0
SLANG_RAW("    [ForceInline]\n")
2134
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
2135
0
SLANG_RAW("    T Sample(SamplerState s, vector<float, Shape.dimensions+isArray> location)\n")
2136
0
SLANG_RAW("    {\n")
2137
0
SLANG_RAW("        __requireComputeDerivative();\n")
2138
0
SLANG_RAW("        __target_switch\n")
2139
0
SLANG_RAW("        {\n")
2140
0
SLANG_RAW("            case cpp:\n")
2141
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2142
0
SLANG_RAW("            case hlsl:\n")
2143
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2144
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2145
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2146
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2147
0
SLANG_RAW("            case metal:\n")
2148
0
SLANG_RAW("                if (isArray == 1)\n")
2149
0
SLANG_RAW("                {\n")
2150
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2151
0
SLANG_RAW("                    {\n")
2152
0
SLANG_RAW("                    case ")
2153
0
SLANG_SPLICE(SLANG_TEXTURE_1D
2154
0
)
2155
0
SLANG_RAW(":\n")
2156
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).x, uint(($2).y))$z\";\n")
2157
0
SLANG_RAW("                    case ")
2158
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2159
0
)
2160
0
SLANG_RAW(":\n")
2161
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z))$z\";\n")
2162
0
SLANG_RAW("                    case ")
2163
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2164
0
)
2165
0
SLANG_RAW(":\n")
2166
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xyz, uint(($2).w))$z\";\n")
2167
0
SLANG_RAW("                    }\n")
2168
0
SLANG_RAW("                }\n")
2169
0
SLANG_RAW("                else\n")
2170
0
SLANG_RAW("                {\n")
2171
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2172
0
SLANG_RAW("                    {\n")
2173
0
SLANG_RAW("                    case ")
2174
0
SLANG_SPLICE(SLANG_TEXTURE_1D
2175
0
)
2176
0
SLANG_RAW(":\n")
2177
0
SLANG_RAW("                    case ")
2178
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2179
0
)
2180
0
SLANG_RAW(":\n")
2181
0
SLANG_RAW("                    case ")
2182
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2183
0
)
2184
0
SLANG_RAW(":\n")
2185
0
SLANG_RAW("                    case ")
2186
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2187
0
)
2188
0
SLANG_RAW(":\n")
2189
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2)$z\";\n")
2190
0
SLANG_RAW("                    }\n")
2191
0
SLANG_RAW("                }\n")
2192
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
2193
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
2194
0
SLANG_RAW("            case glsl:\n")
2195
0
SLANG_RAW("                __intrinsic_asm \"$ctexture($p, $2)$z\";\n")
2196
0
SLANG_RAW("            case cuda:\n")
2197
0
SLANG_RAW("                if (isArray != 0)\n")
2198
0
SLANG_RAW("                {\n")
2199
0
SLANG_RAW("                    switch(Shape.flavor)\n")
2200
0
SLANG_RAW("                    {\n")
2201
0
SLANG_RAW("                    case ")
2202
0
SLANG_SPLICE(SLANG_TEXTURE_1D
2203
0
)
2204
0
SLANG_RAW(":\n")
2205
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLayered<$T0>($0, ($2).x, int(($2).y))\";\n")
2206
0
SLANG_RAW("                    case ")
2207
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2208
0
)
2209
0
SLANG_RAW(":\n")
2210
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLayered<$T0>($0, ($2).x, ($2).y, int(($2).z))\";\n")
2211
0
SLANG_RAW("                    case ")
2212
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2213
0
)
2214
0
SLANG_RAW(":\n")
2215
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLayered<$T0>($0, ($2).x, ($2).y, ($2).z, int(($2).w))\";\n")
2216
0
SLANG_RAW("                    default:\n")
2217
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
2218
0
SLANG_RAW("                    }\n")
2219
0
SLANG_RAW("                }\n")
2220
0
SLANG_RAW("                else\n")
2221
0
SLANG_RAW("                {\n")
2222
0
SLANG_RAW("                    switch(Shape.flavor)\n")
2223
0
SLANG_RAW("                    {\n")
2224
0
SLANG_RAW("                    case ")
2225
0
SLANG_SPLICE(SLANG_TEXTURE_1D
2226
0
)
2227
0
SLANG_RAW(":\n")
2228
0
SLANG_RAW("                        __intrinsic_asm \"tex1D<$T0>($0, ($2))\";\n")
2229
0
SLANG_RAW("                    case ")
2230
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2231
0
)
2232
0
SLANG_RAW(":\n")
2233
0
SLANG_RAW("                        __intrinsic_asm \"tex2D<$T0>($0, ($2).x, ($2).y)\";\n")
2234
0
SLANG_RAW("                    case ")
2235
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2236
0
)
2237
0
SLANG_RAW(":\n")
2238
0
SLANG_RAW("                        __intrinsic_asm \"tex3D<$T0>($0, ($2).x, ($2).y, ($2).z)\";\n")
2239
0
SLANG_RAW("                    case ")
2240
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2241
0
)
2242
0
SLANG_RAW(":\n")
2243
0
SLANG_RAW("                        __intrinsic_asm \"texCubemap<$T0>($0, ($2).x, ($2).y, ($2).z)\";\n")
2244
0
SLANG_RAW("                    default:\n")
2245
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
2246
0
SLANG_RAW("                    }\n")
2247
0
SLANG_RAW("                }\n")
2248
0
SLANG_RAW("            case spirv:\n")
2249
0
SLANG_RAW("                return spirv_asm\n")
2250
0
SLANG_RAW("                {\n")
2251
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2252
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod %sampledImage $location None;\n")
2253
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
2254
0
SLANG_RAW("                };\n")
2255
0
SLANG_RAW("            case wgsl:\n")
2256
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2257
0
SLANG_RAW("\n")
2258
0
SLANG_RAW("                if (isArray == 1)\n")
2259
0
SLANG_RAW("                {\n")
2260
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2261
0
SLANG_RAW("                    {\n")
2262
0
SLANG_RAW("                    case ")
2263
0
SLANG_SPLICE(SLANG_TEXTURE_1D
2264
0
)
2265
0
SLANG_RAW(":\n")
2266
0
SLANG_RAW("                        __intrinsic_asm \"textureSample($0, $1, ($2).x, i32(($2).y))$z\";\n")
2267
0
SLANG_RAW("                    case ")
2268
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2269
0
)
2270
0
SLANG_RAW(":\n")
2271
0
SLANG_RAW("                        __intrinsic_asm \"textureSample($0, $1, ($2).xy, i32(($2).z))$z\";\n")
2272
0
SLANG_RAW("                    case ")
2273
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2274
0
)
2275
0
SLANG_RAW(":\n")
2276
0
SLANG_RAW("                        __intrinsic_asm \"textureSample($0, $1, ($2).xyz, i32(($2).w))$z\";\n")
2277
0
SLANG_RAW("                    default:\n")
2278
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2279
0
SLANG_RAW("                    }\n")
2280
0
SLANG_RAW("                }\n")
2281
0
SLANG_RAW("                __intrinsic_asm \"textureSample($0, $1, $2)$z\";\n")
2282
0
SLANG_RAW("        }\n")
2283
0
SLANG_RAW("    }\n")
2284
0
SLANG_RAW("\n")
2285
0
SLANG_RAW("\n")
2286
0
SLANG_RAW("    [__readNone]\n")
2287
0
SLANG_RAW("    [ForceInline]\n")
2288
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
2289
0
SLANG_RAW("    T Sample(SamplerState s, vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset)\n")
2290
0
SLANG_RAW("    {\n")
2291
0
SLANG_RAW("        __requireComputeDerivative();\n")
2292
0
SLANG_RAW("        __target_switch\n")
2293
0
SLANG_RAW("        {\n")
2294
0
SLANG_RAW("            case cpp:\n")
2295
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2296
0
SLANG_RAW("            case hlsl:\n")
2297
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2298
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2299
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2300
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2301
0
SLANG_RAW("            case metal:\n")
2302
0
SLANG_RAW("                if (isArray == 1)\n")
2303
0
SLANG_RAW("                {\n")
2304
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2305
0
SLANG_RAW("                    {\n")
2306
0
SLANG_RAW("                    case ")
2307
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2308
0
)
2309
0
SLANG_RAW(":\n")
2310
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), $3)$z\";\n")
2311
0
SLANG_RAW("                    }\n")
2312
0
SLANG_RAW("                }\n")
2313
0
SLANG_RAW("                else\n")
2314
0
SLANG_RAW("                {\n")
2315
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2316
0
SLANG_RAW("                    {\n")
2317
0
SLANG_RAW("                    case ")
2318
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2319
0
)
2320
0
SLANG_RAW(":\n")
2321
0
SLANG_RAW("                    case ")
2322
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2323
0
)
2324
0
SLANG_RAW(":\n")
2325
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, $3)$z\";\n")
2326
0
SLANG_RAW("                    }\n")
2327
0
SLANG_RAW("                }\n")
2328
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
2329
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
2330
0
SLANG_RAW("            case glsl:\n")
2331
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffset($p, $2, $3)$z\";\n")
2332
0
SLANG_RAW("            case spirv:\n")
2333
0
SLANG_RAW("                return spirv_asm\n")
2334
0
SLANG_RAW("                {\n")
2335
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2336
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod %sampledImage $location None|ConstOffset $offset;\n")
2337
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
2338
0
SLANG_RAW("                };\n")
2339
0
SLANG_RAW("            case wgsl:\n")
2340
0
SLANG_RAW("                __wgsl_check_texture_type_texel_offset<\n")
2341
0
SLANG_RAW("                    T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2342
0
SLANG_RAW("\n")
2343
0
SLANG_RAW("                if (isArray == 1)\n")
2344
0
SLANG_RAW("                {\n")
2345
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2346
0
SLANG_RAW("                    {\n")
2347
0
SLANG_RAW("                    case ")
2348
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2349
0
)
2350
0
SLANG_RAW(":\n")
2351
0
SLANG_RAW("                        __intrinsic_asm \"textureSample($0, $1, ($2).xy, i32(($2).z), $3)$z\";\n")
2352
0
SLANG_RAW("                    default:\n")
2353
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2354
0
SLANG_RAW("                    }\n")
2355
0
SLANG_RAW("                }\n")
2356
0
SLANG_RAW("                __intrinsic_asm \"textureSample($0, $1, $2, $3)$z\";\n")
2357
0
SLANG_RAW("        }\n")
2358
0
SLANG_RAW("    }\n")
2359
0
SLANG_RAW("\n")
2360
0
SLANG_RAW("    [__readNone]\n")
2361
0
SLANG_RAW("    [ForceInline]\n")
2362
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
2363
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv, texture_sm_4_0_fragment)]\n")
2364
0
SLANG_RAW("    T Sample(SamplerState s, vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset, float clamp)\n")
2365
0
SLANG_RAW("    {\n")
2366
0
SLANG_RAW("        __requireComputeDerivative();\n")
2367
0
SLANG_RAW("        __target_switch\n")
2368
0
SLANG_RAW("        {\n")
2369
0
SLANG_RAW("            case cpp:\n")
2370
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2371
0
SLANG_RAW("            case hlsl:\n")
2372
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2373
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2374
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2375
0
SLANG_RAW("                __intrinsic_asm \".Sample\";\n")
2376
0
SLANG_RAW("            case metal:\n")
2377
0
SLANG_RAW("                if (isArray == 1)\n")
2378
0
SLANG_RAW("                {\n")
2379
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2380
0
SLANG_RAW("                    {\n")
2381
0
SLANG_RAW("                    case ")
2382
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2383
0
)
2384
0
SLANG_RAW(":\n")
2385
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), min_lod_clamp($4), $3)$z\";\n")
2386
0
SLANG_RAW("                    }\n")
2387
0
SLANG_RAW("                }\n")
2388
0
SLANG_RAW("                else\n")
2389
0
SLANG_RAW("                {\n")
2390
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2391
0
SLANG_RAW("                    {\n")
2392
0
SLANG_RAW("                    case ")
2393
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2394
0
)
2395
0
SLANG_RAW(":\n")
2396
0
SLANG_RAW("                    case ")
2397
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2398
0
)
2399
0
SLANG_RAW(":\n")
2400
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, min_lod_clamp($4), $3)$z\";\n")
2401
0
SLANG_RAW("                    }\n")
2402
0
SLANG_RAW("                }\n")
2403
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
2404
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
2405
0
SLANG_RAW("            case glsl:\n")
2406
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffsetClampARB($p, $2, $3, $4)$z\";\n")
2407
0
SLANG_RAW("            case spirv:\n")
2408
0
SLANG_RAW("                return spirv_asm\n")
2409
0
SLANG_RAW("                {\n")
2410
0
SLANG_RAW("                    OpCapability MinLod;\n")
2411
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2412
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod %sampledImage $location None|ConstOffset|MinLod $offset $clamp;\n")
2413
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
2414
0
SLANG_RAW("                };\n")
2415
0
SLANG_RAW("        }\n")
2416
0
SLANG_RAW("    }\n")
2417
0
SLANG_RAW("\n")
2418
0
SLANG_RAW("    [__readNone]\n")
2419
0
SLANG_RAW("    [ForceInline]\n")
2420
0
SLANG_RAW("    T Sample(SamplerState s, vector<float, Shape.dimensions+isArray> location, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
2421
0
SLANG_RAW("    {\n")
2422
0
SLANG_RAW("        __requireComputeDerivative();\n")
2423
0
SLANG_RAW("        __target_switch\n")
2424
0
SLANG_RAW("        {\n")
2425
0
SLANG_RAW("        case hlsl:\n")
2426
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2427
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2428
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2429
0
SLANG_RAW("            __intrinsic_asm \".Sample\";\n")
2430
0
SLANG_RAW("        case spirv:\n")
2431
0
SLANG_RAW("            return spirv_asm\n")
2432
0
SLANG_RAW("            {\n")
2433
0
SLANG_RAW("                OpCapability MinLod;\n")
2434
0
SLANG_RAW("                OpCapability SparseResidency;\n")
2435
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
2436
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
2437
0
SLANG_RAW("\n")
2438
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod %sampledImage $location ConstOffset|MinLod $offset $clamp;\n")
2439
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
2440
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
2441
0
SLANG_RAW("\n")
2442
0
SLANG_RAW("                OpStore &status %residentCode;\n")
2443
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
2444
0
SLANG_RAW("            };\n")
2445
0
SLANG_RAW("        default:\n")
2446
0
SLANG_RAW("            status = 0;\n")
2447
0
SLANG_RAW("            return Sample(s, location, offset, clamp);\n")
2448
0
SLANG_RAW("        }\n")
2449
0
SLANG_RAW("    }\n")
2450
0
SLANG_RAW("\n")
2451
0
SLANG_RAW("    [__readNone]\n")
2452
0
SLANG_RAW("    [ForceInline]\n")
2453
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
2454
0
SLANG_RAW("    T SampleBias(SamplerState s, vector<float, Shape.dimensions+isArray> location, float bias)\n")
2455
0
SLANG_RAW("    {\n")
2456
0
SLANG_RAW("        __requireComputeDerivative();\n")
2457
0
SLANG_RAW("        __target_switch\n")
2458
0
SLANG_RAW("        {\n")
2459
0
SLANG_RAW("            case cpp:\n")
2460
0
SLANG_RAW("                __intrinsic_asm \".SampleBias\";\n")
2461
0
SLANG_RAW("            case hlsl:\n")
2462
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2463
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2464
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2465
0
SLANG_RAW("                __intrinsic_asm \".SampleBias\";\n")
2466
0
SLANG_RAW("            case metal:\n")
2467
0
SLANG_RAW("                if (isArray == 1)\n")
2468
0
SLANG_RAW("                {\n")
2469
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2470
0
SLANG_RAW("                    {\n")
2471
0
SLANG_RAW("                    case ")
2472
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2473
0
)
2474
0
SLANG_RAW(":\n")
2475
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), bias($3))$z\";\n")
2476
0
SLANG_RAW("                    case ")
2477
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2478
0
)
2479
0
SLANG_RAW(":\n")
2480
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xyz, uint(($2).w), bias($3))$z\";\n")
2481
0
SLANG_RAW("                    }\n")
2482
0
SLANG_RAW("                }\n")
2483
0
SLANG_RAW("                else\n")
2484
0
SLANG_RAW("                {\n")
2485
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2486
0
SLANG_RAW("                    {\n")
2487
0
SLANG_RAW("                    case ")
2488
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2489
0
)
2490
0
SLANG_RAW(":\n")
2491
0
SLANG_RAW("                    case ")
2492
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2493
0
)
2494
0
SLANG_RAW(":\n")
2495
0
SLANG_RAW("                    case ")
2496
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2497
0
)
2498
0
SLANG_RAW(":\n")
2499
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, bias($3))$z\";\n")
2500
0
SLANG_RAW("                    }\n")
2501
0
SLANG_RAW("                }\n")
2502
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
2503
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
2504
0
SLANG_RAW("            case glsl:\n")
2505
0
SLANG_RAW("                __intrinsic_asm \"$ctexture($p, $2, $3)$z\";\n")
2506
0
SLANG_RAW("            case spirv:\n")
2507
0
SLANG_RAW("                return spirv_asm\n")
2508
0
SLANG_RAW("                {\n")
2509
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2510
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod %sampledImage $location None|Bias $bias;\n")
2511
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
2512
0
SLANG_RAW("                };\n")
2513
0
SLANG_RAW("            case wgsl:\n")
2514
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2515
0
SLANG_RAW("\n")
2516
0
SLANG_RAW("                if (isArray == 1)\n")
2517
0
SLANG_RAW("                {\n")
2518
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2519
0
SLANG_RAW("                    {\n")
2520
0
SLANG_RAW("                    case ")
2521
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2522
0
)
2523
0
SLANG_RAW(":\n")
2524
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleBias($0, $1, ($2).xy, i32(($2).z), $3)$z\";\n")
2525
0
SLANG_RAW("                    case ")
2526
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2527
0
)
2528
0
SLANG_RAW(":\n")
2529
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleBias($0, $1, ($2).xyz, i32(($2).w), $3)$z\";\n")
2530
0
SLANG_RAW("                    default:\n")
2531
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2532
0
SLANG_RAW("                    }\n")
2533
0
SLANG_RAW("                }\n")
2534
0
SLANG_RAW("                __intrinsic_asm \"textureSampleBias($0, $1, $2, $3)$z\";\n")
2535
0
SLANG_RAW("        }\n")
2536
0
SLANG_RAW("    }\n")
2537
0
SLANG_RAW("\n")
2538
0
SLANG_RAW("    [__readNone]\n")
2539
0
SLANG_RAW("    [ForceInline]\n")
2540
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0_fragment)]\n")
2541
0
SLANG_RAW("    T SampleBias(SamplerState s, vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset)\n")
2542
0
SLANG_RAW("    {\n")
2543
0
SLANG_RAW("        __requireComputeDerivative();\n")
2544
0
SLANG_RAW("        __target_switch\n")
2545
0
SLANG_RAW("        {\n")
2546
0
SLANG_RAW("            case cpp:\n")
2547
0
SLANG_RAW("                __intrinsic_asm \".SampleBias\";\n")
2548
0
SLANG_RAW("            case hlsl:\n")
2549
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2550
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2551
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2552
0
SLANG_RAW("                __intrinsic_asm \".SampleBias\";\n")
2553
0
SLANG_RAW("            case metal:\n")
2554
0
SLANG_RAW("                if (isArray == 1)\n")
2555
0
SLANG_RAW("                {\n")
2556
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2557
0
SLANG_RAW("                    {\n")
2558
0
SLANG_RAW("                    case ")
2559
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2560
0
)
2561
0
SLANG_RAW(":\n")
2562
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), bias($3), $4)$z\";\n")
2563
0
SLANG_RAW("                    }\n")
2564
0
SLANG_RAW("                }\n")
2565
0
SLANG_RAW("                else\n")
2566
0
SLANG_RAW("                {\n")
2567
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2568
0
SLANG_RAW("                    {\n")
2569
0
SLANG_RAW("                    case ")
2570
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2571
0
)
2572
0
SLANG_RAW(":\n")
2573
0
SLANG_RAW("                    case ")
2574
0
SLANG_SPLICE(SLANG_TEXTURE_3D
2575
0
)
2576
0
SLANG_RAW(":\n")
2577
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, bias($3), $4)$z\";\n")
2578
0
SLANG_RAW("                    }\n")
2579
0
SLANG_RAW("                }\n")
2580
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
2581
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
2582
0
SLANG_RAW("            case glsl:\n")
2583
0
SLANG_RAW("                __intrinsic_asm \"$ctextureOffset($p, $2, $4, $3)$z\";\n")
2584
0
SLANG_RAW("            case spirv:\n")
2585
0
SLANG_RAW("                return spirv_asm\n")
2586
0
SLANG_RAW("                {\n")
2587
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2588
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleImplicitLod %sampledImage $location None|Bias|ConstOffset $bias $offset;\n")
2589
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
2590
0
SLANG_RAW("                };\n")
2591
0
SLANG_RAW("            case wgsl:\n")
2592
0
SLANG_RAW("                __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2593
0
SLANG_RAW("\n")
2594
0
SLANG_RAW("                if (isArray == 1)\n")
2595
0
SLANG_RAW("                {\n")
2596
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2597
0
SLANG_RAW("                    {\n")
2598
0
SLANG_RAW("                    case ")
2599
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2600
0
)
2601
0
SLANG_RAW(":\n")
2602
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleBias($0, $1, ($2).xy, i32(($2).z), $3, $4)$z\";\n")
2603
0
SLANG_RAW("                    default:\n")
2604
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2605
0
SLANG_RAW("                    }\n")
2606
0
SLANG_RAW("                }\n")
2607
0
SLANG_RAW("                __intrinsic_asm \"textureSampleBias($0, $1, $2, $3, $4)$z\";\n")
2608
0
SLANG_RAW("        }\n")
2609
0
SLANG_RAW("    }\n")
2610
0
SLANG_RAW("\n")
2611
0
SLANG_RAW("    [__readNone]\n")
2612
0
SLANG_RAW("    [ForceInline]\n")
2613
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
2614
0
SLANG_RAW("    T SampleBias(SamplerState s, vector<float, Shape.dimensions+isArray> location, float bias, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
2615
0
SLANG_RAW("    {\n")
2616
0
SLANG_RAW("        __requireComputeDerivative();\n")
2617
0
SLANG_RAW("        __target_switch\n")
2618
0
SLANG_RAW("        {\n")
2619
0
SLANG_RAW("        case hlsl:\n")
2620
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2621
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2622
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2623
0
SLANG_RAW("            __intrinsic_asm \".SampleBias\";\n")
2624
0
SLANG_RAW("        case spirv:\n")
2625
0
SLANG_RAW("            return spirv_asm\n")
2626
0
SLANG_RAW("            {\n")
2627
0
SLANG_RAW("                OpCapability MinLod;\n")
2628
0
SLANG_RAW("                OpCapability SparseResidency;\n")
2629
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
2630
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
2631
0
SLANG_RAW("\n")
2632
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleImplicitLod %sampledImage $location Bias|ConstOffset|MinLod $bias $offset $clamp;\n")
2633
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
2634
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
2635
0
SLANG_RAW("\n")
2636
0
SLANG_RAW("                OpStore &status %residentCode;\n")
2637
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
2638
0
SLANG_RAW("            };\n")
2639
0
SLANG_RAW("       }\n")
2640
0
SLANG_RAW("    }\n")
2641
0
SLANG_RAW("\n")
2642
0
SLANG_RAW("    [__readNone]\n")
2643
0
SLANG_RAW("    [ForceInline]\n")
2644
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
2645
0
SLANG_RAW("    float SampleCmp(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue)\n")
2646
0
SLANG_RAW("    {\n")
2647
0
SLANG_RAW("        __requireComputeDerivative();\n")
2648
0
SLANG_RAW("        __target_switch\n")
2649
0
SLANG_RAW("        {\n")
2650
0
SLANG_RAW("        case glsl:\n")
2651
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
2652
0
SLANG_RAW("            {\n")
2653
0
SLANG_RAW("                return __glsl_texture_1d_shadow(this, s, __makeVector(__makeVector(location, 0.0), compareValue));\n")
2654
0
SLANG_RAW("            }\n")
2655
0
SLANG_RAW("            else if (Shape.dimensions == 3 && isArray == 1)\n")
2656
0
SLANG_RAW("            {\n")
2657
0
SLANG_RAW("                return __glsl_texture_3d_array_shadow(this, s, location, compareValue);\n")
2658
0
SLANG_RAW("            }\n")
2659
0
SLANG_RAW("            else\n")
2660
0
SLANG_RAW("            {\n")
2661
0
SLANG_RAW("                return __glsl_texture(this, s, __makeVector(location,compareValue));\n")
2662
0
SLANG_RAW("            }\n")
2663
0
SLANG_RAW("        case hlsl:\n")
2664
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2665
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2666
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2667
0
SLANG_RAW("            __intrinsic_asm \".SampleCmp\";\n")
2668
0
SLANG_RAW("        case metal:\n")
2669
0
SLANG_RAW("            return __metal_SampleCmp(__metal_asDepthTexture(this), s, location, compareValue);\n")
2670
0
SLANG_RAW("        case spirv:\n")
2671
0
SLANG_RAW("            return spirv_asm\n")
2672
0
SLANG_RAW("            {\n")
2673
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2674
0
SLANG_RAW("                result:$$float = OpImageSampleDrefImplicitLod %sampledImage $location $compareValue;\n")
2675
0
SLANG_RAW("            };\n")
2676
0
SLANG_RAW("        case wgsl:\n")
2677
0
SLANG_RAW("            __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2678
0
SLANG_RAW("\n")
2679
0
SLANG_RAW("            if (isArray == 1)\n")
2680
0
SLANG_RAW("            {\n")
2681
0
SLANG_RAW("                switch (Shape.flavor)\n")
2682
0
SLANG_RAW("                {\n")
2683
0
SLANG_RAW("                case ")
2684
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2685
0
)
2686
0
SLANG_RAW(":\n")
2687
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompare($0, $1, ($2).xy, i32(($2).z), $3)\";\n")
2688
0
SLANG_RAW("                case ")
2689
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2690
0
)
2691
0
SLANG_RAW(":\n")
2692
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompare($0, $1, ($2).xyz, i32(($2).w), $3)\";\n")
2693
0
SLANG_RAW("                default:\n")
2694
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2695
0
SLANG_RAW("                }\n")
2696
0
SLANG_RAW("            }\n")
2697
0
SLANG_RAW("            __intrinsic_asm \"textureSampleCompare($0, $1, $2, $3)\";\n")
2698
0
SLANG_RAW("        }\n")
2699
0
SLANG_RAW("    }\n")
2700
0
SLANG_RAW("\n")
2701
0
SLANG_RAW("    [__readNone]\n")
2702
0
SLANG_RAW("    [ForceInline]\n")
2703
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
2704
0
SLANG_RAW("    float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue)\n")
2705
0
SLANG_RAW("    {\n")
2706
0
SLANG_RAW("        __target_switch\n")
2707
0
SLANG_RAW("        {\n")
2708
0
SLANG_RAW("        case hlsl:\n")
2709
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2710
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2711
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2712
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevelZero\";\n")
2713
0
SLANG_RAW("        case wgsl:\n")
2714
0
SLANG_RAW("            __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2715
0
SLANG_RAW("\n")
2716
0
SLANG_RAW("            if (isArray == 1)\n")
2717
0
SLANG_RAW("            {\n")
2718
0
SLANG_RAW("                switch (Shape.flavor)\n")
2719
0
SLANG_RAW("                {\n")
2720
0
SLANG_RAW("                case ")
2721
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2722
0
)
2723
0
SLANG_RAW(":\n")
2724
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompareLevel($0, $1, ($2).xy, i32(($2).z), $3)\";\n")
2725
0
SLANG_RAW("                case ")
2726
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2727
0
)
2728
0
SLANG_RAW(":\n")
2729
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompareLevel($0, $1, ($2).xyz, i32(($2).w), $3)\";\n")
2730
0
SLANG_RAW("                default:\n")
2731
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2732
0
SLANG_RAW("                }\n")
2733
0
SLANG_RAW("            }\n")
2734
0
SLANG_RAW("            __intrinsic_asm \"textureSampleCompareLevel($0, $1, $2, $3)\";\n")
2735
0
SLANG_RAW("        default:\n")
2736
0
SLANG_RAW("            return SampleCmpLevel(s, location, compareValue, 0.0);\n")
2737
0
SLANG_RAW("        }\n")
2738
0
SLANG_RAW("    }\n")
2739
0
SLANG_RAW("\n")
2740
0
SLANG_RAW("    [__readNone]\n")
2741
0
SLANG_RAW("    [ForceInline]\n")
2742
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
2743
0
SLANG_RAW("    float SampleCmp(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)\n")
2744
0
SLANG_RAW("    {\n")
2745
0
SLANG_RAW("        __requireComputeDerivative();\n")
2746
0
SLANG_RAW("        __target_switch\n")
2747
0
SLANG_RAW("        {\n")
2748
0
SLANG_RAW("        case glsl:\n")
2749
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
2750
0
SLANG_RAW("            {\n")
2751
0
SLANG_RAW("                return __glsl_texture_offset_1d_shadow(this, s, __makeVector(__makeVector(location, 0.0), compareValue), offset);\n")
2752
0
SLANG_RAW("            }\n")
2753
0
SLANG_RAW("            else\n")
2754
0
SLANG_RAW("            {\n")
2755
0
SLANG_RAW("                return __glsl_texture_offset(this, s, __makeVector(location,compareValue), offset);\n")
2756
0
SLANG_RAW("            }\n")
2757
0
SLANG_RAW("        case hlsl:\n")
2758
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2759
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2760
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2761
0
SLANG_RAW("            __intrinsic_asm \".SampleCmp\";\n")
2762
0
SLANG_RAW("        case metal:\n")
2763
0
SLANG_RAW("            return __metal_SampleCmp(__metal_asDepthTexture(this), s, location, compareValue, offset);\n")
2764
0
SLANG_RAW("        case spirv:\n")
2765
0
SLANG_RAW("            return spirv_asm\n")
2766
0
SLANG_RAW("            {\n")
2767
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2768
0
SLANG_RAW("                result:$$float = OpImageSampleDrefImplicitLod %sampledImage $location $compareValue ConstOffset $offset;\n")
2769
0
SLANG_RAW("            };\n")
2770
0
SLANG_RAW("        case wgsl:\n")
2771
0
SLANG_RAW("            __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2772
0
SLANG_RAW("\n")
2773
0
SLANG_RAW("            if (isArray == 1)\n")
2774
0
SLANG_RAW("            {\n")
2775
0
SLANG_RAW("                switch (Shape.flavor)\n")
2776
0
SLANG_RAW("                {\n")
2777
0
SLANG_RAW("                case ")
2778
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2779
0
)
2780
0
SLANG_RAW(":\n")
2781
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompare($0, $1, ($2).xy, i32(($2).z), $3, $4)\";\n")
2782
0
SLANG_RAW("                default:\n")
2783
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2784
0
SLANG_RAW("                }\n")
2785
0
SLANG_RAW("            }\n")
2786
0
SLANG_RAW("            __intrinsic_asm \"textureSampleCompare($0, $1, $2, $3, $4)\";\n")
2787
0
SLANG_RAW("        }\n")
2788
0
SLANG_RAW("    }\n")
2789
0
SLANG_RAW("\n")
2790
0
SLANG_RAW("    [__readNone]\n")
2791
0
SLANG_RAW("    [ForceInline]\n")
2792
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
2793
0
SLANG_RAW("    float SampleCmp(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, float clamp, out uint status)\n")
2794
0
SLANG_RAW("    {\n")
2795
0
SLANG_RAW("        __requireComputeDerivative();\n")
2796
0
SLANG_RAW("        __target_switch\n")
2797
0
SLANG_RAW("        {\n")
2798
0
SLANG_RAW("        case hlsl:\n")
2799
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2800
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2801
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2802
0
SLANG_RAW("            __intrinsic_asm \".SampleCmp\";\n")
2803
0
SLANG_RAW("        case spirv:\n")
2804
0
SLANG_RAW("            return spirv_asm\n")
2805
0
SLANG_RAW("            {\n")
2806
0
SLANG_RAW("                OpCapability MinLod;\n")
2807
0
SLANG_RAW("                OpCapability SparseResidency;\n")
2808
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint $$float;\n")
2809
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
2810
0
SLANG_RAW("\n")
2811
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleDrefImplicitLod %sampledImage $location $compareValue ConstOffset|MinLod $offset $clamp;\n")
2812
0
SLANG_RAW("\n")
2813
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
2814
0
SLANG_RAW("                OpStore &status %residentCode;\n")
2815
0
SLANG_RAW("                result:$$float = OpCompositeExtract %sparseResult 1;\n")
2816
0
SLANG_RAW("            };\n")
2817
0
SLANG_RAW("        }\n")
2818
0
SLANG_RAW("    }\n")
2819
0
SLANG_RAW("\n")
2820
0
SLANG_RAW("    [__readNone]\n")
2821
0
SLANG_RAW("    [ForceInline]\n")
2822
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv_wgsl, texture_shadowlod)]\n")
2823
0
SLANG_RAW("    float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset)\n")
2824
0
SLANG_RAW("    {\n")
2825
0
SLANG_RAW("        __target_switch\n")
2826
0
SLANG_RAW("        {\n")
2827
0
SLANG_RAW("        case hlsl:\n")
2828
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2829
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2830
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2831
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevelZero\";\n")
2832
0
SLANG_RAW("        case wgsl:\n")
2833
0
SLANG_RAW("            __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
2834
0
SLANG_RAW("\n")
2835
0
SLANG_RAW("            if (isArray == 1)\n")
2836
0
SLANG_RAW("            {\n")
2837
0
SLANG_RAW("                switch (Shape.flavor)\n")
2838
0
SLANG_RAW("                {\n")
2839
0
SLANG_RAW("                case ")
2840
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2841
0
)
2842
0
SLANG_RAW(":\n")
2843
0
SLANG_RAW("                    __intrinsic_asm \"textureSampleCompareLevel($0, $1, ($2).xy, i32(($2).z), $3, $4)\";\n")
2844
0
SLANG_RAW("                default:\n")
2845
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
2846
0
SLANG_RAW("                }\n")
2847
0
SLANG_RAW("            }\n")
2848
0
SLANG_RAW("            __intrinsic_asm \"textureSampleCompareLevel($0, $1, $2, $3, $4)\";\n")
2849
0
SLANG_RAW("        default:\n")
2850
0
SLANG_RAW("            return SampleCmpLevel(s, location, compareValue, 0.0, offset);\n")
2851
0
SLANG_RAW("        }\n")
2852
0
SLANG_RAW("    }\n")
2853
0
SLANG_RAW("\n")
2854
0
SLANG_RAW("    [__readNone]\n")
2855
0
SLANG_RAW("    [ForceInline]\n")
2856
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
2857
0
SLANG_RAW("    float SampleCmpLevelZero(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
2858
0
SLANG_RAW("    {\n")
2859
0
SLANG_RAW("        __target_switch\n")
2860
0
SLANG_RAW("        {\n")
2861
0
SLANG_RAW("        case hlsl:\n")
2862
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2863
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2864
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2865
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevelZero\";\n")
2866
0
SLANG_RAW("        case spirv:\n")
2867
0
SLANG_RAW("            return SampleCmpLevel(s, location, compareValue, 0.0, offset, status);\n")
2868
0
SLANG_RAW("        }\n")
2869
0
SLANG_RAW("    }\n")
2870
0
SLANG_RAW("\n")
2871
0
SLANG_RAW("    [__readNone]\n")
2872
0
SLANG_RAW("    [ForceInline]\n")
2873
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_shadowlod)]\n")
2874
0
SLANG_RAW("    float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level)\n")
2875
0
SLANG_RAW("    {\n")
2876
0
SLANG_RAW("        __target_switch\n")
2877
0
SLANG_RAW("        {\n")
2878
0
SLANG_RAW("        case glsl:\n")
2879
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
2880
0
SLANG_RAW("            {\n")
2881
0
SLANG_RAW("                return __glsl_texture_level_1d_shadow(this, s, __makeVector(__makeVector(location, 0.0), compareValue), level);\n")
2882
0
SLANG_RAW("            }\n")
2883
0
SLANG_RAW("            else\n")
2884
0
SLANG_RAW("            {\n")
2885
0
SLANG_RAW("                return __glsl_texture_level(this, s, __makeVector(location,compareValue), level);\n")
2886
0
SLANG_RAW("            }\n")
2887
0
SLANG_RAW("        case hlsl:\n")
2888
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2889
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2890
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2891
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevel\";\n")
2892
0
SLANG_RAW("        case metal:\n")
2893
0
SLANG_RAW("            return __metal_SampleCmpLevel(__metal_asDepthTexture(this), s, location, compareValue, level);\n")
2894
0
SLANG_RAW("        case spirv:\n")
2895
0
SLANG_RAW("            return spirv_asm\n")
2896
0
SLANG_RAW("            {\n")
2897
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2898
0
SLANG_RAW("                result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod $level;\n")
2899
0
SLANG_RAW("            };\n")
2900
0
SLANG_RAW("        }\n")
2901
0
SLANG_RAW("    }\n")
2902
0
SLANG_RAW("\n")
2903
0
SLANG_RAW("    [__readNone]\n")
2904
0
SLANG_RAW("    [ForceInline]\n")
2905
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, texture_shadowlod)]\n")
2906
0
SLANG_RAW("    float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset)\n")
2907
0
SLANG_RAW("    {\n")
2908
0
SLANG_RAW("        __target_switch\n")
2909
0
SLANG_RAW("        {\n")
2910
0
SLANG_RAW("        case glsl:\n")
2911
0
SLANG_RAW("            if (Shape.dimensions == 1 && isArray == 0)\n")
2912
0
SLANG_RAW("            {\n")
2913
0
SLANG_RAW("                return __glsl_texture_level_offset_1d_shadow(this, s, __makeVector(__makeVector(location,0.0),compareValue), level, offset);\n")
2914
0
SLANG_RAW("            }\n")
2915
0
SLANG_RAW("            else\n")
2916
0
SLANG_RAW("            {\n")
2917
0
SLANG_RAW("                return __glsl_texture_level_offset(this, s, __makeVector(location,compareValue), level, offset);\n")
2918
0
SLANG_RAW("            }\n")
2919
0
SLANG_RAW("        case hlsl:\n")
2920
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2921
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2922
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2923
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevel\";\n")
2924
0
SLANG_RAW("        case metal:\n")
2925
0
SLANG_RAW("            return __metal_SampleCmpLevel(__metal_asDepthTexture(this), s, location, compareValue, level, offset);\n")
2926
0
SLANG_RAW("        case spirv:\n")
2927
0
SLANG_RAW("            return spirv_asm\n")
2928
0
SLANG_RAW("            {\n")
2929
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
2930
0
SLANG_RAW("                result:$$float = OpImageSampleDrefExplicitLod %sampledImage $location $compareValue Lod|ConstOffset $level $offset;\n")
2931
0
SLANG_RAW("            };\n")
2932
0
SLANG_RAW("        }\n")
2933
0
SLANG_RAW("    }\n")
2934
0
SLANG_RAW("\n")
2935
0
SLANG_RAW("    [__readNone]\n")
2936
0
SLANG_RAW("    [ForceInline]\n")
2937
0
SLANG_RAW("    [require(hlsl_spirv, texture_shadowlod)]\n")
2938
0
SLANG_RAW("    float SampleCmpLevel(SamplerComparisonState s, vector<float, Shape.dimensions+isArray> location, float compareValue, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
2939
0
SLANG_RAW("    {\n")
2940
0
SLANG_RAW("        __target_switch\n")
2941
0
SLANG_RAW("        {\n")
2942
0
SLANG_RAW("        case hlsl:\n")
2943
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2944
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2945
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
2946
0
SLANG_RAW("            __intrinsic_asm \".SampleCmpLevel\";\n")
2947
0
SLANG_RAW("        case spirv:\n")
2948
0
SLANG_RAW("            return spirv_asm\n")
2949
0
SLANG_RAW("            {\n")
2950
0
SLANG_RAW("                OpCapability SparseResidency;\n")
2951
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint $$float;\n")
2952
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
2953
0
SLANG_RAW("\n")
2954
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleDrefExplicitLod %sampledImage $location $compareValue Lod|ConstOffset $level $offset;\n")
2955
0
SLANG_RAW("\n")
2956
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
2957
0
SLANG_RAW("                OpStore &status %residentCode;\n")
2958
0
SLANG_RAW("                result:$$float = OpCompositeExtract %sparseResult 1;\n")
2959
0
SLANG_RAW("            };\n")
2960
0
SLANG_RAW("        }\n")
2961
0
SLANG_RAW("    }\n")
2962
0
SLANG_RAW("\n")
2963
0
SLANG_RAW("    [__readNone]\n")
2964
0
SLANG_RAW("    [ForceInline]\n")
2965
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
2966
0
SLANG_RAW("    T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY)\n")
2967
0
SLANG_RAW("    {\n")
2968
0
SLANG_RAW("        __target_switch\n")
2969
0
SLANG_RAW("        {\n")
2970
0
SLANG_RAW("            case cpp:\n")
2971
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
2972
0
SLANG_RAW("            case hlsl:\n")
2973
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
2974
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
2975
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
2976
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
2977
0
SLANG_RAW("            case metal:\n")
2978
0
SLANG_RAW("                if (isArray == 1)\n")
2979
0
SLANG_RAW("                {\n")
2980
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2981
0
SLANG_RAW("                    {\n")
2982
0
SLANG_RAW("                    case ")
2983
0
SLANG_SPLICE(SLANG_TEXTURE_2D
2984
0
)
2985
0
SLANG_RAW(":\n")
2986
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), gradient2d($3, $4))$z\";\n")
2987
0
SLANG_RAW("                    case ")
2988
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
2989
0
)
2990
0
SLANG_RAW(":\n")
2991
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xyz, uint(($2).w), gradientcube($3, $4))$z\";\n")
2992
0
SLANG_RAW("                    }\n")
2993
0
SLANG_RAW("                }\n")
2994
0
SLANG_RAW("                else\n")
2995
0
SLANG_RAW("                {\n")
2996
0
SLANG_RAW("                    switch (Shape.flavor)\n")
2997
0
SLANG_RAW("                    {\n")
2998
0
SLANG_RAW("                    case ")
2999
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3000
0
)
3001
0
SLANG_RAW(":\n")
3002
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient2d($3, $4))$z\";\n")
3003
0
SLANG_RAW("                    case ")
3004
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3005
0
)
3006
0
SLANG_RAW(":\n")
3007
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient3d($3, $4))$z\";\n")
3008
0
SLANG_RAW("                    case ")
3009
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3010
0
)
3011
0
SLANG_RAW(":\n")
3012
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradientcube($3, $4))$z\";\n")
3013
0
SLANG_RAW("                    }\n")
3014
0
SLANG_RAW("                }\n")
3015
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
3016
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
3017
0
SLANG_RAW("            case glsl:\n")
3018
0
SLANG_RAW("            __intrinsic_asm \"$ctextureGrad($p, $2, $3, $4)$z\";\n")
3019
0
SLANG_RAW("            case spirv:\n")
3020
0
SLANG_RAW("                return spirv_asm\n")
3021
0
SLANG_RAW("                {\n")
3022
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
3023
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod %sampledImage $location None|Grad $gradX $gradY;\n")
3024
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
3025
0
SLANG_RAW("                };\n")
3026
0
SLANG_RAW("            case wgsl:\n")
3027
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3028
0
SLANG_RAW("\n")
3029
0
SLANG_RAW("                if (isArray == 1)\n")
3030
0
SLANG_RAW("                {\n")
3031
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3032
0
SLANG_RAW("                    {\n")
3033
0
SLANG_RAW("                    case ")
3034
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3035
0
)
3036
0
SLANG_RAW(":\n")
3037
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleGrad($0, $1, ($2).xy, i32(($2).z), $3, $4)$z\";\n")
3038
0
SLANG_RAW("                    case ")
3039
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3040
0
)
3041
0
SLANG_RAW(":\n")
3042
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleGrad($0, $1, ($2).xyz, i32(($2).w), $3, $4)$z\";\n")
3043
0
SLANG_RAW("                    default:\n")
3044
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3045
0
SLANG_RAW("                    }\n")
3046
0
SLANG_RAW("                }\n")
3047
0
SLANG_RAW("                __intrinsic_asm \"textureSampleGrad($0, $1, $2, $3, $4)$z\";\n")
3048
0
SLANG_RAW("        }\n")
3049
0
SLANG_RAW("    }\n")
3050
0
SLANG_RAW("\n")
3051
0
SLANG_RAW("    [__readNone]\n")
3052
0
SLANG_RAW("    [ForceInline]\n")
3053
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
3054
0
SLANG_RAW("    T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset)\n")
3055
0
SLANG_RAW("    {\n")
3056
0
SLANG_RAW("        __target_switch\n")
3057
0
SLANG_RAW("        {\n")
3058
0
SLANG_RAW("            case cpp:\n")
3059
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
3060
0
SLANG_RAW("            case hlsl:\n")
3061
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3062
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3063
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
3064
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
3065
0
SLANG_RAW("            case metal:\n")
3066
0
SLANG_RAW("                if (isArray == 1)\n")
3067
0
SLANG_RAW("                {\n")
3068
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3069
0
SLANG_RAW("                    {\n")
3070
0
SLANG_RAW("                    case ")
3071
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3072
0
)
3073
0
SLANG_RAW(":\n")
3074
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), gradient2d($3, $4), $5)$z\";\n")
3075
0
SLANG_RAW("                    }\n")
3076
0
SLANG_RAW("                }\n")
3077
0
SLANG_RAW("                else\n")
3078
0
SLANG_RAW("                {\n")
3079
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3080
0
SLANG_RAW("                    {\n")
3081
0
SLANG_RAW("                    case ")
3082
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3083
0
)
3084
0
SLANG_RAW(":\n")
3085
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient2d($3, $4), $5)$z\";\n")
3086
0
SLANG_RAW("                    case ")
3087
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3088
0
)
3089
0
SLANG_RAW(":\n")
3090
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient3d($3, $4), $5)$z\";\n")
3091
0
SLANG_RAW("                    }\n")
3092
0
SLANG_RAW("                }\n")
3093
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
3094
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
3095
0
SLANG_RAW("            case glsl:\n")
3096
0
SLANG_RAW("            __intrinsic_asm \"$ctextureGradOffset($p, $2, $3, $4, $5)$z\";\n")
3097
0
SLANG_RAW("            case spirv:\n")
3098
0
SLANG_RAW("                return spirv_asm\n")
3099
0
SLANG_RAW("                {\n")
3100
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
3101
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod %sampledImage $location None|Grad|ConstOffset $gradX $gradY $offset;\n")
3102
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
3103
0
SLANG_RAW("\n")
3104
0
SLANG_RAW("                };\n")
3105
0
SLANG_RAW("            case wgsl:\n")
3106
0
SLANG_RAW("                __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3107
0
SLANG_RAW("\n")
3108
0
SLANG_RAW("                if (isArray == 1)\n")
3109
0
SLANG_RAW("                {\n")
3110
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3111
0
SLANG_RAW("                    {\n")
3112
0
SLANG_RAW("                    case ")
3113
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3114
0
)
3115
0
SLANG_RAW(":\n")
3116
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleGrad($0, $1, ($2).xy, i32(($2).z), $3, $4, $5)$z\";\n")
3117
0
SLANG_RAW("                    default:\n")
3118
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3119
0
SLANG_RAW("                    }\n")
3120
0
SLANG_RAW("                }\n")
3121
0
SLANG_RAW("                __intrinsic_asm \"textureSampleGrad($0, $1, $2, $3, $4, $5)$z\";\n")
3122
0
SLANG_RAW("        }\n")
3123
0
SLANG_RAW("    }\n")
3124
0
SLANG_RAW("\n")
3125
0
SLANG_RAW("    [__readNone]\n")
3126
0
SLANG_RAW("    [ForceInline]\n")
3127
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
3128
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv, texture_sm_4_0)]\n")
3129
0
SLANG_RAW("    T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp)\n")
3130
0
SLANG_RAW("    {\n")
3131
0
SLANG_RAW("        __target_switch\n")
3132
0
SLANG_RAW("        {\n")
3133
0
SLANG_RAW("            case cpp:\n")
3134
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
3135
0
SLANG_RAW("            case hlsl:\n")
3136
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3137
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3138
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
3139
0
SLANG_RAW("                __intrinsic_asm \".SampleGrad\";\n")
3140
0
SLANG_RAW("            case metal:\n")
3141
0
SLANG_RAW("                if (isArray == 1)\n")
3142
0
SLANG_RAW("                {\n")
3143
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3144
0
SLANG_RAW("                    {\n")
3145
0
SLANG_RAW("                    case ")
3146
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3147
0
)
3148
0
SLANG_RAW(":\n")
3149
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), gradient2d($3, $4), min_lod_clamp($6), $5)$z\";\n")
3150
0
SLANG_RAW("                    }\n")
3151
0
SLANG_RAW("                }\n")
3152
0
SLANG_RAW("                else\n")
3153
0
SLANG_RAW("                {\n")
3154
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3155
0
SLANG_RAW("                    {\n")
3156
0
SLANG_RAW("                    case ")
3157
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3158
0
)
3159
0
SLANG_RAW(":\n")
3160
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient2d($3, $4), min_lod_clamp($6), $5)$z\";\n")
3161
0
SLANG_RAW("                    case ")
3162
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3163
0
)
3164
0
SLANG_RAW(":\n")
3165
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, gradient3d($3, $4), min_lod_clamp($6), $5)$z\";\n")
3166
0
SLANG_RAW("                    }\n")
3167
0
SLANG_RAW("                }\n")
3168
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
3169
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
3170
0
SLANG_RAW("            case glsl:\n")
3171
0
SLANG_RAW("            __intrinsic_asm \"$ctextureGradOffsetClampARB($p, $2, $3, $4, $5, $6)$z\";\n")
3172
0
SLANG_RAW("            case spirv:\n")
3173
0
SLANG_RAW("                return spirv_asm\n")
3174
0
SLANG_RAW("                {\n")
3175
0
SLANG_RAW("                    OpCapability MinLod;\n")
3176
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
3177
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod %sampledImage $location None|Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp;\n")
3178
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
3179
0
SLANG_RAW("                };\n")
3180
0
SLANG_RAW("        }\n")
3181
0
SLANG_RAW("    }\n")
3182
0
SLANG_RAW("\n")
3183
0
SLANG_RAW("    [__readNone]\n")
3184
0
SLANG_RAW("    [ForceInline]\n")
3185
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
3186
0
SLANG_RAW("    T SampleGrad(SamplerState s, vector<float, Shape.dimensions+isArray> location, vector<float, Shape.dimensions> gradX, vector<float, Shape.dimensions> gradY, constexpr vector<int, Shape.dimensions> offset, float lodClamp, out uint status)\n")
3187
0
SLANG_RAW("    {\n")
3188
0
SLANG_RAW("        __target_switch\n")
3189
0
SLANG_RAW("        {\n")
3190
0
SLANG_RAW("        case hlsl:\n")
3191
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3192
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3193
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
3194
0
SLANG_RAW("            __intrinsic_asm \".SampleGrad\";\n")
3195
0
SLANG_RAW("        case spirv:\n")
3196
0
SLANG_RAW("            return spirv_asm\n")
3197
0
SLANG_RAW("            {\n")
3198
0
SLANG_RAW("                OpCapability MinLod;\n")
3199
0
SLANG_RAW("                OpCapability SparseResidency;\n")
3200
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
3201
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
3202
0
SLANG_RAW("\n")
3203
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod %sampledImage $location Grad|ConstOffset|MinLod $gradX $gradY $offset $lodClamp;\n")
3204
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
3205
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
3206
0
SLANG_RAW("\n")
3207
0
SLANG_RAW("                OpStore &status %residentCode;\n")
3208
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
3209
0
SLANG_RAW("            };\n")
3210
0
SLANG_RAW("       }\n")
3211
0
SLANG_RAW("    }\n")
3212
0
SLANG_RAW("\n")
3213
0
SLANG_RAW("    [__readNone]\n")
3214
0
SLANG_RAW("    [ForceInline]\n")
3215
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
3216
0
SLANG_RAW("    T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, float level)\n")
3217
0
SLANG_RAW("    {\n")
3218
0
SLANG_RAW("        __target_switch\n")
3219
0
SLANG_RAW("        {\n")
3220
0
SLANG_RAW("            case cpp:\n")
3221
0
SLANG_RAW("                __intrinsic_asm \".SampleLevel\";\n")
3222
0
SLANG_RAW("            case hlsl:\n")
3223
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3224
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3225
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
3226
0
SLANG_RAW("                __intrinsic_asm \".SampleLevel\";\n")
3227
0
SLANG_RAW("            case metal:\n")
3228
0
SLANG_RAW("                if (isArray == 1)\n")
3229
0
SLANG_RAW("                {\n")
3230
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3231
0
SLANG_RAW("                    {\n")
3232
0
SLANG_RAW("                    case ")
3233
0
SLANG_SPLICE(SLANG_TEXTURE_1D
3234
0
)
3235
0
SLANG_RAW(":\n")
3236
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).x, uint(($2).y))$z\";\n")
3237
0
SLANG_RAW("                    case ")
3238
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3239
0
)
3240
0
SLANG_RAW(":\n")
3241
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), level($3))$z\";\n")
3242
0
SLANG_RAW("                    case ")
3243
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3244
0
)
3245
0
SLANG_RAW(":\n")
3246
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xyz, uint(($2).w), level($3))$z\";\n")
3247
0
SLANG_RAW("                    }\n")
3248
0
SLANG_RAW("                }\n")
3249
0
SLANG_RAW("                else\n")
3250
0
SLANG_RAW("                {\n")
3251
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3252
0
SLANG_RAW("                    {\n")
3253
0
SLANG_RAW("                    case ")
3254
0
SLANG_SPLICE(SLANG_TEXTURE_1D
3255
0
)
3256
0
SLANG_RAW(":\n")
3257
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2)$z\";\n")
3258
0
SLANG_RAW("                    case ")
3259
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3260
0
)
3261
0
SLANG_RAW(":\n")
3262
0
SLANG_RAW("                    case ")
3263
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3264
0
)
3265
0
SLANG_RAW(":\n")
3266
0
SLANG_RAW("                    case ")
3267
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3268
0
)
3269
0
SLANG_RAW(":\n")
3270
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, level($3))$z\";\n")
3271
0
SLANG_RAW("                    }\n")
3272
0
SLANG_RAW("                }\n")
3273
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
3274
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
3275
0
SLANG_RAW("            case glsl:\n")
3276
0
SLANG_RAW("                __intrinsic_asm \"$ctextureLod($p, $2, $3)$z\";\n")
3277
0
SLANG_RAW("            case cuda:\n")
3278
0
SLANG_RAW("                if (isArray != 0)\n")
3279
0
SLANG_RAW("                {\n")
3280
0
SLANG_RAW("                    switch(Shape.flavor)\n")
3281
0
SLANG_RAW("                    {\n")
3282
0
SLANG_RAW("                    case ")
3283
0
SLANG_SPLICE(SLANG_TEXTURE_1D
3284
0
)
3285
0
SLANG_RAW(":\n")
3286
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLayeredLod<$T0>($0, ($2).x, int(($2).y), ($3))\";\n")
3287
0
SLANG_RAW("                    case ")
3288
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3289
0
)
3290
0
SLANG_RAW(":\n")
3291
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLayeredLod<$T0>($0, ($2).x, ($2).y, int(($2).z), ($3))\";\n")
3292
0
SLANG_RAW("                    case ")
3293
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3294
0
)
3295
0
SLANG_RAW(":\n")
3296
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLayeredLod<$T0>($0, ($2).x, ($2).y, ($2).z, int(($2).w), ($3))\";\n")
3297
0
SLANG_RAW("                    default:\n")
3298
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
3299
0
SLANG_RAW("                    }\n")
3300
0
SLANG_RAW("                }\n")
3301
0
SLANG_RAW("                else\n")
3302
0
SLANG_RAW("                {\n")
3303
0
SLANG_RAW("                    switch(Shape.flavor)\n")
3304
0
SLANG_RAW("                    {\n")
3305
0
SLANG_RAW("                    case ")
3306
0
SLANG_SPLICE(SLANG_TEXTURE_1D
3307
0
)
3308
0
SLANG_RAW(":\n")
3309
0
SLANG_RAW("                        __intrinsic_asm \"tex1DLod<$T0>($0, ($2), ($3))\";\n")
3310
0
SLANG_RAW("                    case ")
3311
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3312
0
)
3313
0
SLANG_RAW(":\n")
3314
0
SLANG_RAW("                        __intrinsic_asm \"tex2DLod<$T0>($0, ($2).x, ($2).y, ($3))\";\n")
3315
0
SLANG_RAW("                    case ")
3316
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3317
0
)
3318
0
SLANG_RAW(":\n")
3319
0
SLANG_RAW("                        __intrinsic_asm \"tex3DLod<$T0>($0, ($2).x, ($2).y, ($2).z, ($3))\";\n")
3320
0
SLANG_RAW("                    case ")
3321
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3322
0
)
3323
0
SLANG_RAW(":\n")
3324
0
SLANG_RAW("                        __intrinsic_asm \"texCubemapLod<$T0>($0, ($2).x, ($2).y, ($2).z, ($3))\";\n")
3325
0
SLANG_RAW("                    default:\n")
3326
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
3327
0
SLANG_RAW("                    }\n")
3328
0
SLANG_RAW("                }\n")
3329
0
SLANG_RAW("            case spirv:\n")
3330
0
SLANG_RAW("                return spirv_asm\n")
3331
0
SLANG_RAW("                {\n")
3332
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
3333
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod %sampledImage $location None|Lod $level;\n")
3334
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
3335
0
SLANG_RAW("                };\n")
3336
0
SLANG_RAW("            case wgsl:\n")
3337
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3338
0
SLANG_RAW("\n")
3339
0
SLANG_RAW("                if (isArray == 1)\n")
3340
0
SLANG_RAW("                {\n")
3341
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3342
0
SLANG_RAW("                    {\n")
3343
0
SLANG_RAW("                    case ")
3344
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3345
0
)
3346
0
SLANG_RAW(":\n")
3347
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleLevel($0, $1, ($2).xy, i32(($2).z), $3)$z\";\n")
3348
0
SLANG_RAW("                    case ")
3349
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3350
0
)
3351
0
SLANG_RAW(":\n")
3352
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleLevel($0, $1, ($2).xyz, i32(($2).w), $3)$z\";\n")
3353
0
SLANG_RAW("                    default:\n")
3354
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3355
0
SLANG_RAW("                    }\n")
3356
0
SLANG_RAW("                }\n")
3357
0
SLANG_RAW("                __intrinsic_asm \"textureSampleLevel($0, $1, $2, $3)$z\";\n")
3358
0
SLANG_RAW("        }\n")
3359
0
SLANG_RAW("    }\n")
3360
0
SLANG_RAW("\n")
3361
0
SLANG_RAW("    [__readNone]\n")
3362
0
SLANG_RAW("    [ForceInline]\n")
3363
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_0)]\n")
3364
0
SLANG_RAW("    T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset)\n")
3365
0
SLANG_RAW("    {\n")
3366
0
SLANG_RAW("        __target_switch\n")
3367
0
SLANG_RAW("        {\n")
3368
0
SLANG_RAW("            case cpp:\n")
3369
0
SLANG_RAW("                __intrinsic_asm \".SampleLevel\";\n")
3370
0
SLANG_RAW("            case hlsl:\n")
3371
0
SLANG_RAW("                static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3372
0
SLANG_RAW("                    || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3373
0
SLANG_RAW("                    , \"HLSL supports only float and half type textures\");\n")
3374
0
SLANG_RAW("                __intrinsic_asm \".SampleLevel\";\n")
3375
0
SLANG_RAW("            case metal:\n")
3376
0
SLANG_RAW("                if (isArray == 1)\n")
3377
0
SLANG_RAW("                {\n")
3378
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3379
0
SLANG_RAW("                    {\n")
3380
0
SLANG_RAW("                    case ")
3381
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3382
0
)
3383
0
SLANG_RAW(":\n")
3384
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xy, uint(($2).z), level($3), $4)$z\";\n")
3385
0
SLANG_RAW("                    case ")
3386
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3387
0
)
3388
0
SLANG_RAW(":\n")
3389
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, ($2).xyz, uint(($2).w), level($3), $4)$z\";\n")
3390
0
SLANG_RAW("                    }\n")
3391
0
SLANG_RAW("                }\n")
3392
0
SLANG_RAW("                else\n")
3393
0
SLANG_RAW("                {\n")
3394
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3395
0
SLANG_RAW("                    {\n")
3396
0
SLANG_RAW("                    case ")
3397
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3398
0
)
3399
0
SLANG_RAW(":\n")
3400
0
SLANG_RAW("                    case ")
3401
0
SLANG_SPLICE(SLANG_TEXTURE_3D
3402
0
)
3403
0
SLANG_RAW(":\n")
3404
0
SLANG_RAW("                    case ")
3405
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3406
0
)
3407
0
SLANG_RAW(":\n")
3408
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.sample($1, $2, level($3), $4)$z\";\n")
3409
0
SLANG_RAW("                    }\n")
3410
0
SLANG_RAW("                }\n")
3411
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic>\";\n")
3412
0
SLANG_RAW("            case glsl:\n")
3413
0
SLANG_RAW("                __intrinsic_asm \"$ctextureLodOffset($p, $2, $3, $4)$z\";\n")
3414
0
SLANG_RAW("            case spirv:\n")
3415
0
SLANG_RAW("                return spirv_asm\n")
3416
0
SLANG_RAW("                {\n")
3417
0
SLANG_RAW("                    %sampledImage : __sampledImageType(this) = OpSampledImage $this $s;\n")
3418
0
SLANG_RAW("                    %sampled : __sampledType(T) = OpImageSampleExplicitLod %sampledImage $location None|Lod|ConstOffset $level $offset;\n")
3419
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
3420
0
SLANG_RAW("                };\n")
3421
0
SLANG_RAW("            case wgsl:\n")
3422
0
SLANG_RAW("                __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3423
0
SLANG_RAW("\n")
3424
0
SLANG_RAW("                if (isArray == 1)\n")
3425
0
SLANG_RAW("                {\n")
3426
0
SLANG_RAW("                    switch (Shape.flavor)\n")
3427
0
SLANG_RAW("                    {\n")
3428
0
SLANG_RAW("                    case ")
3429
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3430
0
)
3431
0
SLANG_RAW(":\n")
3432
0
SLANG_RAW("                        __intrinsic_asm \"textureSampleLevel($0, $1, ($2).xy, i32(($2).z), $3, $4)$z\";\n")
3433
0
SLANG_RAW("                    default:\n")
3434
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3435
0
SLANG_RAW("                    }\n")
3436
0
SLANG_RAW("                }\n")
3437
0
SLANG_RAW("                __intrinsic_asm \"textureSampleLevel($0, $1, $2, $3, $4)$z\";\n")
3438
0
SLANG_RAW("        }\n")
3439
0
SLANG_RAW("    }\n")
3440
0
SLANG_RAW("\n")
3441
0
SLANG_RAW("    [__readNone]\n")
3442
0
SLANG_RAW("    [ForceInline]\n")
3443
0
SLANG_RAW("    [require(hlsl_spirv, sm_5_0)]\n")
3444
0
SLANG_RAW("    T SampleLevel(SamplerState s, vector<float, Shape.dimensions+isArray> location, float level, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
3445
0
SLANG_RAW("    {\n")
3446
0
SLANG_RAW("        __target_switch\n")
3447
0
SLANG_RAW("        {\n")
3448
0
SLANG_RAW("        case hlsl:\n")
3449
0
SLANG_RAW("            static_assert(T is float || T is vector<float,2> || T is vector<float,3> || T is vector<float,4>\n")
3450
0
SLANG_RAW("                || T is half || T is vector<half,2> || T is vector<half,3> || T is vector<half,4>\n")
3451
0
SLANG_RAW("                , \"HLSL supports only float and half type textures\");\n")
3452
0
SLANG_RAW("            __intrinsic_asm \".SampleLevel\";\n")
3453
0
SLANG_RAW("        case spirv:\n")
3454
0
SLANG_RAW("            return spirv_asm\n")
3455
0
SLANG_RAW("            {\n")
3456
0
SLANG_RAW("                OpCapability SparseResidency;\n")
3457
0
SLANG_RAW("                %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
3458
0
SLANG_RAW("                %sampledImage:__sampledImageType(this) = OpSampledImage $this $s;\n")
3459
0
SLANG_RAW("\n")
3460
0
SLANG_RAW("                %sparseResult:%sparseResultType = OpImageSparseSampleExplicitLod %sampledImage $location Lod|ConstOffset $level $offset;\n")
3461
0
SLANG_RAW("                %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
3462
0
SLANG_RAW("                %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
3463
0
SLANG_RAW("\n")
3464
0
SLANG_RAW("                OpStore &status %residentCode;\n")
3465
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
3466
0
SLANG_RAW("            };\n")
3467
0
SLANG_RAW("        }\n")
3468
0
SLANG_RAW("    }\n")
3469
0
SLANG_RAW("}\n")
3470
0
SLANG_RAW("\n")
3471
0
SLANG_RAW("// Texture.GetDimensions and Sampler.GetDimensions\n")
3472
3473
0
const char* kTextureShapeTypeNames[] = {
3474
0
    "__Shape1D", "__Shape2D", "__Shape3D", "__ShapeCube"};
3475
0
for (int shapeIndex = 0; shapeIndex < 4; shapeIndex++)
3476
0
for (int isArray = 0; isArray <= 1; isArray++)
3477
0
for (int isMS = 0; isMS <= 1; isMS++) {
3478
0
    if (isMS)
3479
0
    {
3480
0
        if (shapeIndex != kCoreModule_ShapeIndex2D)
3481
0
            continue;
3482
0
    }
3483
0
    if (isArray)
3484
0
    {
3485
0
        if (shapeIndex == kCoreModule_ShapeIndex3D)
3486
0
            continue;
3487
0
    }
3488
0
    auto shapeTypeName = kTextureShapeTypeNames[shapeIndex];
3489
0
    TextureTypeInfo textureTypeInfo(kBaseTextureShapes[shapeIndex], isArray, isMS, 0, sb, path);
3490
0
SLANG_RAW("#line 3050 \"hlsl.meta.slang\"")
3491
0
SLANG_RAW("\n")
3492
0
SLANG_RAW("\n")
3493
0
SLANG_RAW("__generic<T:ITexelElement, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
3494
0
SLANG_RAW("extension _Texture<T,")
3495
0
SLANG_SPLICE(shapeTypeName
3496
0
)
3497
0
SLANG_RAW(",")
3498
0
SLANG_SPLICE(isArray
3499
0
)
3500
0
SLANG_RAW(",")
3501
0
SLANG_SPLICE(isMS
3502
0
)
3503
0
SLANG_RAW(",sampleCount,access,isShadow,isCombined,format>\n")
3504
0
SLANG_RAW("{\n")
3505
3506
0
    textureTypeInfo.writeGetDimensionFunctions();
3507
    
3508
0
SLANG_RAW("#line 3057 \"hlsl.meta.slang\"")
3509
0
SLANG_RAW("\n")
3510
0
SLANG_RAW("}\n")
3511
0
SLANG_RAW("\n")
3512
3513
0
}
3514
0
SLANG_RAW("#line 3062 \"hlsl.meta.slang\"")
3515
0
SLANG_RAW("\n")
3516
0
SLANG_RAW("\n")
3517
0
SLANG_RAW("// Texture.GetSamplePosition(int s);\n")
3518
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
3519
0
SLANG_RAW("extension _Texture<T,Shape,isArray,1,sampleCount,access,isShadow,isCombined,format>\n")
3520
0
SLANG_RAW("{\n")
3521
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_spirv, texture_sm_4_1_vertex_fragment_geometry)]\n")
3522
0
SLANG_RAW("    float2 GetSamplePosition(int s);\n")
3523
0
SLANG_RAW("}\n")
3524
0
SLANG_RAW("\n")
3525
0
SLANG_RAW("__intrinsic_op(")
3526
0
SLANG_SPLICE(kIROp_MakeArray
3527
0
)
3528
0
SLANG_RAW(")\n")
3529
0
SLANG_RAW("Array<T,4> __makeArray<T>(T v0, T v1, T v2, T v3);\n")
3530
0
SLANG_RAW("\n")
3531
0
SLANG_RAW("\n")
3532
0
SLANG_RAW("// Beginning of Texture Gather\n")
3533
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3534
0
SLANG_RAW("[ForceInline]\n")
3535
0
SLANG_RAW("[require(glsl_metal_spirv_wgsl, texture_gather)]\n")
3536
0
SLANG_RAW("vector<T.Element,4> __texture_gather(\n")
3537
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3538
0
SLANG_RAW("    SamplerState s,\n")
3539
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3540
0
SLANG_RAW("    int component)\n")
3541
0
SLANG_RAW("{\n")
3542
0
SLANG_RAW("    static const int isMS = 0;\n")
3543
0
SLANG_RAW("    static const int isCombined = 0;\n")
3544
0
SLANG_RAW("\n")
3545
0
SLANG_RAW("    __target_switch\n")
3546
0
SLANG_RAW("    {\n")
3547
0
SLANG_RAW("    case glsl:\n")
3548
0
SLANG_RAW("        __intrinsic_asm \"textureGather($p, $2, $3)\";\n")
3549
0
SLANG_RAW("    case metal:\n")
3550
0
SLANG_RAW("        if (isArray == 1)\n")
3551
0
SLANG_RAW("        {\n")
3552
0
SLANG_RAW("            switch (Shape.flavor)\n")
3553
0
SLANG_RAW("            {\n")
3554
0
SLANG_RAW("            case ")
3555
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3556
0
)
3557
0
SLANG_RAW(":\n")
3558
0
SLANG_RAW("                // Tv gather(sampler s, float2 coord, uint array, int2 offset = int2(0), component c = component::x) const\n")
3559
0
SLANG_RAW("                __intrinsic_asm \"$0.gather($1, ($2).xy, uint(($2).z), int2(0), metal::component($3))\";\n")
3560
0
SLANG_RAW("            case ")
3561
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3562
0
)
3563
0
SLANG_RAW(":\n")
3564
0
SLANG_RAW("                // Tv gather(sampler s, float3 coord, uint array, component c = component::x) const\n")
3565
0
SLANG_RAW("                __intrinsic_asm \"$0.gather($1, ($2).xyz, uint(($2).w), metal::component($3))\";\n")
3566
0
SLANG_RAW("            }\n")
3567
0
SLANG_RAW("        }\n")
3568
0
SLANG_RAW("        if (Shape.flavor == ")
3569
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3570
0
)
3571
0
SLANG_RAW(")\n")
3572
0
SLANG_RAW("        {\n")
3573
0
SLANG_RAW("            // Tv gather(sampler s, float3 coord, component c = component::x) const\n")
3574
0
SLANG_RAW("            __intrinsic_asm \"$0.gather($1, $2, metal::component($3))\";\n")
3575
0
SLANG_RAW("        }\n")
3576
0
SLANG_RAW("        // Tv gather(sampler s, float2 coord, int2 offset = int2(0), component c = component::x) const\n")
3577
0
SLANG_RAW("        __intrinsic_asm \"$0.gather($1, $2, int2(0), metal::component($3))\";\n")
3578
0
SLANG_RAW("    case spirv:\n")
3579
0
SLANG_RAW("        return spirv_asm {\n")
3580
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
3581
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather %sampledImage $location $component;\n")
3582
0
SLANG_RAW("        };\n")
3583
0
SLANG_RAW("    case wgsl:\n")
3584
0
SLANG_RAW("        __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3585
0
SLANG_RAW("\n")
3586
0
SLANG_RAW("        if (isShadow == 1)\n")
3587
0
SLANG_RAW("        {\n")
3588
0
SLANG_RAW("            // If depth texture, `textureGather` doesn't take channel value, `$3`.\n")
3589
0
SLANG_RAW("            if (isArray == 1)\n")
3590
0
SLANG_RAW("            {\n")
3591
0
SLANG_RAW("                switch (Shape.flavor)\n")
3592
0
SLANG_RAW("                {\n")
3593
0
SLANG_RAW("                case ")
3594
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3595
0
)
3596
0
SLANG_RAW(":\n")
3597
0
SLANG_RAW("                    __intrinsic_asm \"textureGather($0, $1, ($2).xy, u32(($2).z))\";\n")
3598
0
SLANG_RAW("                case ")
3599
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3600
0
)
3601
0
SLANG_RAW(":\n")
3602
0
SLANG_RAW("                    __intrinsic_asm \"textureGather($0, $1, ($2).xyz, u32(($2).w))\";\n")
3603
0
SLANG_RAW("                default:\n")
3604
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3605
0
SLANG_RAW("                }\n")
3606
0
SLANG_RAW("            }\n")
3607
0
SLANG_RAW("            __intrinsic_asm \"textureGather($0, $1, $2)\";\n")
3608
0
SLANG_RAW("        }\n")
3609
0
SLANG_RAW("\n")
3610
0
SLANG_RAW("        if (isArray == 1)\n")
3611
0
SLANG_RAW("        {\n")
3612
0
SLANG_RAW("            switch (Shape.flavor)\n")
3613
0
SLANG_RAW("            {\n")
3614
0
SLANG_RAW("            case ")
3615
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3616
0
)
3617
0
SLANG_RAW(":\n")
3618
0
SLANG_RAW("                __intrinsic_asm \"textureGather($3, $0, $1, ($2).xy, u32(($2).z))\";\n")
3619
0
SLANG_RAW("            case ")
3620
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3621
0
)
3622
0
SLANG_RAW(":\n")
3623
0
SLANG_RAW("                __intrinsic_asm \"textureGather($3, $0, $1, ($2).xyz, u32(($2).w))\";\n")
3624
0
SLANG_RAW("            default:\n")
3625
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3626
0
SLANG_RAW("            }\n")
3627
0
SLANG_RAW("        }\n")
3628
0
SLANG_RAW("        __intrinsic_asm \"textureGather($3, $0, $1, $2)\";\n")
3629
0
SLANG_RAW("    }\n")
3630
0
SLANG_RAW("}\n")
3631
0
SLANG_RAW("\n")
3632
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3633
0
SLANG_RAW("[ForceInline]\n")
3634
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3635
0
SLANG_RAW("vector<T.Element,4> __texture_gather(\n")
3636
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
3637
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3638
0
SLANG_RAW("    int component)\n")
3639
0
SLANG_RAW("{\n")
3640
0
SLANG_RAW("    __target_switch\n")
3641
0
SLANG_RAW("    {\n")
3642
0
SLANG_RAW("    case glsl:\n")
3643
0
SLANG_RAW("        __intrinsic_asm \"textureGather($0, $1, $2)\";\n")
3644
0
SLANG_RAW("    case spirv:\n")
3645
0
SLANG_RAW("        return spirv_asm {\n")
3646
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather $sampler $location $component;\n")
3647
0
SLANG_RAW("        };\n")
3648
0
SLANG_RAW("    }\n")
3649
0
SLANG_RAW("}\n")
3650
0
SLANG_RAW("\n")
3651
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3652
0
SLANG_RAW("[ForceInline]\n")
3653
0
SLANG_RAW("[require(glsl_metal_spirv_wgsl, texture_gather)]\n")
3654
0
SLANG_RAW("vector<T.Element,4> __texture_gather_offset(\n")
3655
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3656
0
SLANG_RAW("    SamplerState s,\n")
3657
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3658
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset,\n")
3659
0
SLANG_RAW("    int component)\n")
3660
0
SLANG_RAW("{\n")
3661
0
SLANG_RAW("    static const int isMS = 0;\n")
3662
0
SLANG_RAW("    static const int isCombined = 0;\n")
3663
0
SLANG_RAW("\n")
3664
0
SLANG_RAW("    __target_switch\n")
3665
0
SLANG_RAW("    {\n")
3666
0
SLANG_RAW("    case glsl:\n")
3667
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffset($p, $2, $3, $4)\";\n")
3668
0
SLANG_RAW("    case metal:\n")
3669
0
SLANG_RAW("        static_assert(Shape.flavor == ")
3670
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3671
0
)
3672
0
SLANG_RAW(",\n")
3673
0
SLANG_RAW("            \"Metal supports offset variant of Gather only for 2D textures\");\n")
3674
0
SLANG_RAW("\n")
3675
0
SLANG_RAW("        if (isArray == 1)\n")
3676
0
SLANG_RAW("        {\n")
3677
0
SLANG_RAW("            // Tv gather(sampler s, float2 coord, uint array, int2 offset = int2(0), component c = component::x) const\n")
3678
0
SLANG_RAW("            __intrinsic_asm \"$0.gather($1, ($2).xy, uint(($2).z), $3, metal::component($4))\";\n")
3679
0
SLANG_RAW("        }\n")
3680
0
SLANG_RAW("        // Tv gather(sampler s, float2 coord, int2 offset = int2(0), component c = component::x) const\n")
3681
0
SLANG_RAW("        __intrinsic_asm \"$0.gather($1, $2, $3, metal::component($4))\";\n")
3682
0
SLANG_RAW("    case spirv:\n")
3683
0
SLANG_RAW("        return spirv_asm {\n")
3684
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
3685
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
3686
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather %sampledImage $location $component Offset $offset;\n")
3687
0
SLANG_RAW("        };\n")
3688
0
SLANG_RAW("    case wgsl:\n")
3689
0
SLANG_RAW("        __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3690
0
SLANG_RAW("        static_assert(Shape.flavor == ")
3691
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3692
0
)
3693
0
SLANG_RAW("\n")
3694
0
SLANG_RAW("            , \"WGSL texture gather with offset is supported only on 2D textures\");\n")
3695
0
SLANG_RAW("\n")
3696
0
SLANG_RAW("        if (isShadow == 1)\n")
3697
0
SLANG_RAW("        {\n")
3698
0
SLANG_RAW("            // If depth texture, `textureGather` doesn't take channel value, `$4`.\n")
3699
0
SLANG_RAW("            if (isArray == 1)\n")
3700
0
SLANG_RAW("            {\n")
3701
0
SLANG_RAW("                switch (Shape.flavor)\n")
3702
0
SLANG_RAW("                {\n")
3703
0
SLANG_RAW("                case ")
3704
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3705
0
)
3706
0
SLANG_RAW(":\n")
3707
0
SLANG_RAW("                    __intrinsic_asm \"textureGather($0, $1, ($2).xy, u32(($2).z), $3)\";\n")
3708
0
SLANG_RAW("                default:\n")
3709
0
SLANG_RAW("                    __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3710
0
SLANG_RAW("                }\n")
3711
0
SLANG_RAW("            }\n")
3712
0
SLANG_RAW("            __intrinsic_asm \"textureGather($0, $1, $2, $3)\";\n")
3713
0
SLANG_RAW("        }\n")
3714
0
SLANG_RAW("\n")
3715
0
SLANG_RAW("        if (isArray == 1)\n")
3716
0
SLANG_RAW("        {\n")
3717
0
SLANG_RAW("            switch (Shape.flavor)\n")
3718
0
SLANG_RAW("            {\n")
3719
0
SLANG_RAW("            case ")
3720
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3721
0
)
3722
0
SLANG_RAW(":\n")
3723
0
SLANG_RAW("                __intrinsic_asm \"textureGather($4, $0, $1, ($2).xy, u32(($2).z), $3)\";\n")
3724
0
SLANG_RAW("            default:\n")
3725
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3726
0
SLANG_RAW("            }\n")
3727
0
SLANG_RAW("        }\n")
3728
0
SLANG_RAW("        __intrinsic_asm \"textureGather($4, $0, $1, $2, $3)\";\n")
3729
0
SLANG_RAW("    }\n")
3730
0
SLANG_RAW("}\n")
3731
0
SLANG_RAW("\n")
3732
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3733
0
SLANG_RAW("[ForceInline]\n")
3734
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3735
0
SLANG_RAW("vector<T.Element,4> __texture_gather_offset(\n")
3736
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
3737
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3738
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset,\n")
3739
0
SLANG_RAW("    int component)\n")
3740
0
SLANG_RAW("{\n")
3741
0
SLANG_RAW("    __target_switch\n")
3742
0
SLANG_RAW("    {\n")
3743
0
SLANG_RAW("    case glsl:\n")
3744
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffset($0, $1, $2, $3)\";\n")
3745
0
SLANG_RAW("    case spirv:\n")
3746
0
SLANG_RAW("        return spirv_asm {\n")
3747
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
3748
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather $sampler $location $component Offset $offset;\n")
3749
0
SLANG_RAW("        };\n")
3750
0
SLANG_RAW("    }\n")
3751
0
SLANG_RAW("}\n")
3752
0
SLANG_RAW("\n")
3753
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3754
0
SLANG_RAW("[ForceInline]\n")
3755
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3756
0
SLANG_RAW("vector<T.Element,4> __texture_gather_offsets(\n")
3757
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3758
0
SLANG_RAW("    SamplerState s,\n")
3759
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3760
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset1,\n")
3761
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset2,\n")
3762
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset3,\n")
3763
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset4,\n")
3764
0
SLANG_RAW("    int component)\n")
3765
0
SLANG_RAW("{\n")
3766
0
SLANG_RAW("    __target_switch\n")
3767
0
SLANG_RAW("    {\n")
3768
0
SLANG_RAW("    case glsl:\n")
3769
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffsets($p, $2, $T3[]($3, $4, $5, $6)), $7\";\n")
3770
0
SLANG_RAW("    case spirv:\n")
3771
0
SLANG_RAW("        let offsets = __makeArray(offset1,offset2,offset3,offset4);\n")
3772
0
SLANG_RAW("        return spirv_asm {\n")
3773
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
3774
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
3775
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather %sampledImage $location $component ConstOffsets $offsets;\n")
3776
0
SLANG_RAW("        };\n")
3777
0
SLANG_RAW("    }\n")
3778
0
SLANG_RAW("}\n")
3779
0
SLANG_RAW("\n")
3780
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3781
0
SLANG_RAW("[ForceInline]\n")
3782
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3783
0
SLANG_RAW("vector<T.Element,4> __texture_gather_offsets(\n")
3784
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
3785
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3786
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset1,\n")
3787
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset2,\n")
3788
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset3,\n")
3789
0
SLANG_RAW("    constexpr vector<int, Shape.planeDimensions> offset4,\n")
3790
0
SLANG_RAW("    int component)\n")
3791
0
SLANG_RAW("{\n")
3792
0
SLANG_RAW("    __target_switch\n")
3793
0
SLANG_RAW("    {\n")
3794
0
SLANG_RAW("    case glsl:\n")
3795
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffsets($0, $1, $T2[]($2, $3, $4, $5), $6)\";\n")
3796
0
SLANG_RAW("    case spirv:\n")
3797
0
SLANG_RAW("        let offsets = __makeArray(offset1,offset2,offset3,offset4);\n")
3798
0
SLANG_RAW("        return spirv_asm {\n")
3799
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
3800
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageGather $sampler $location $component ConstOffsets $offsets;\n")
3801
0
SLANG_RAW("        };\n")
3802
0
SLANG_RAW("    }\n")
3803
0
SLANG_RAW("}\n")
3804
0
SLANG_RAW("\n")
3805
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3806
0
SLANG_RAW("[ForceInline]\n")
3807
0
SLANG_RAW("[require(glsl_metal_spirv_wgsl, texture_gather)]\n")
3808
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp(\n")
3809
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3810
0
SLANG_RAW("    SamplerComparisonState s,\n")
3811
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3812
0
SLANG_RAW("    T.Element compareValue)\n")
3813
0
SLANG_RAW("{\n")
3814
0
SLANG_RAW("    static const int isMS = 0;\n")
3815
0
SLANG_RAW("    static const int isCombined = 0;\n")
3816
0
SLANG_RAW("\n")
3817
0
SLANG_RAW("    __target_switch\n")
3818
0
SLANG_RAW("    {\n")
3819
0
SLANG_RAW("    case glsl:\n")
3820
0
SLANG_RAW("        __intrinsic_asm \"textureGather($p, $2, $3)\";\n")
3821
0
SLANG_RAW("    case metal:\n")
3822
0
SLANG_RAW("        if (isArray == 1)\n")
3823
0
SLANG_RAW("        {\n")
3824
0
SLANG_RAW("            switch (Shape.flavor)\n")
3825
0
SLANG_RAW("            {\n")
3826
0
SLANG_RAW("            case ")
3827
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3828
0
)
3829
0
SLANG_RAW(":\n")
3830
0
SLANG_RAW("                // Tv gather_compare(sampler s, float2 coord, uint array, float compare_value, int2 offset = int2(0)) const\n")
3831
0
SLANG_RAW("                __intrinsic_asm \"$0.gather_compare($1, ($2).xy, uint(($2).z), $3)\";\n")
3832
0
SLANG_RAW("            case ")
3833
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3834
0
)
3835
0
SLANG_RAW(":\n")
3836
0
SLANG_RAW("                // Tv gather_compare(sampler s, float3 coord, uint array, float compare_value) const\n")
3837
0
SLANG_RAW("                __intrinsic_asm \"$0.gather_compare($1, ($2).xyz, uint(($2).w), $3)\";\n")
3838
0
SLANG_RAW("            }\n")
3839
0
SLANG_RAW("        }\n")
3840
0
SLANG_RAW("        // Tv gather_compare(sampler s, float2 coord, float compare_value, int2 offset = int2(0)) const\n")
3841
0
SLANG_RAW("        __intrinsic_asm \"$0.gather_compare($1, $2, $3)\";\n")
3842
0
SLANG_RAW("    case spirv:\n")
3843
0
SLANG_RAW("        return spirv_asm {\n")
3844
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
3845
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather %sampledImage $location $compareValue;\n")
3846
0
SLANG_RAW("        };\n")
3847
0
SLANG_RAW("    case wgsl:\n")
3848
0
SLANG_RAW("        __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3849
0
SLANG_RAW("        static_assert(Shape.flavor == ")
3850
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3851
0
)
3852
0
SLANG_RAW(" || Shape.flavor == ")
3853
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3854
0
)
3855
0
SLANG_RAW("\n")
3856
0
SLANG_RAW("            , \"WGSL texture gather is supported only on 2D and Cube textures\");\n")
3857
0
SLANG_RAW("\n")
3858
0
SLANG_RAW("        if (isArray == 1)\n")
3859
0
SLANG_RAW("        {\n")
3860
0
SLANG_RAW("            switch (Shape.flavor)\n")
3861
0
SLANG_RAW("            {\n")
3862
0
SLANG_RAW("            case ")
3863
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3864
0
)
3865
0
SLANG_RAW(":\n")
3866
0
SLANG_RAW("                __intrinsic_asm \"textureGatherCompare($0, $1, ($2).xy, u32(($2).z), $3)\";\n")
3867
0
SLANG_RAW("            case ")
3868
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
3869
0
)
3870
0
SLANG_RAW(":\n")
3871
0
SLANG_RAW("                __intrinsic_asm \"textureGatherCompare($0, $1, ($2).xyz, u32(($2).w), $3)\";\n")
3872
0
SLANG_RAW("            default:\n")
3873
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3874
0
SLANG_RAW("            }\n")
3875
0
SLANG_RAW("        }\n")
3876
0
SLANG_RAW("        __intrinsic_asm \"textureGatherCompare($0, $1, $2, $3)\";\n")
3877
0
SLANG_RAW("    }\n")
3878
0
SLANG_RAW("}\n")
3879
0
SLANG_RAW("\n")
3880
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3881
0
SLANG_RAW("[ForceInline]\n")
3882
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3883
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp(\n")
3884
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
3885
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3886
0
SLANG_RAW("    T.Element compareValue)\n")
3887
0
SLANG_RAW("{\n")
3888
0
SLANG_RAW("    __target_switch\n")
3889
0
SLANG_RAW("    {\n")
3890
0
SLANG_RAW("    case glsl:\n")
3891
0
SLANG_RAW("        __intrinsic_asm \"textureGather($0, $1, $2)\";\n")
3892
0
SLANG_RAW("    case spirv:\n")
3893
0
SLANG_RAW("        return spirv_asm {\n")
3894
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather $sampler $location $compareValue;\n")
3895
0
SLANG_RAW("        };\n")
3896
0
SLANG_RAW("    }\n")
3897
0
SLANG_RAW("}\n")
3898
0
SLANG_RAW("\n")
3899
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3900
0
SLANG_RAW("[ForceInline]\n")
3901
0
SLANG_RAW("[require(glsl_metal_spirv_wgsl, texture_gather)]\n")
3902
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp_offset(\n")
3903
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3904
0
SLANG_RAW("    SamplerComparisonState s,\n")
3905
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3906
0
SLANG_RAW("    T.Element compareValue,\n")
3907
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset)\n")
3908
0
SLANG_RAW("{\n")
3909
0
SLANG_RAW("    static const int isMS = 0;\n")
3910
0
SLANG_RAW("    static const int isCombined = 0;\n")
3911
0
SLANG_RAW("\n")
3912
0
SLANG_RAW("    __target_switch\n")
3913
0
SLANG_RAW("    {\n")
3914
0
SLANG_RAW("    case glsl:\n")
3915
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffset($p, $2, $3, $4)\";\n")
3916
0
SLANG_RAW("    case metal:\n")
3917
0
SLANG_RAW("        static_assert(Shape.flavor == ")
3918
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3919
0
)
3920
0
SLANG_RAW(",\n")
3921
0
SLANG_RAW("            \"Metal supports depth compare Gather only for 2D texture\");\n")
3922
0
SLANG_RAW("\n")
3923
0
SLANG_RAW("        if (isArray == 1)\n")
3924
0
SLANG_RAW("        {\n")
3925
0
SLANG_RAW("            // Tv gather_compare(sampler s, float2 coord, uint array, float compare_value, int2 offset = int2(0)) const\n")
3926
0
SLANG_RAW("            __intrinsic_asm \"$0.gather_compare($1, ($2).xy, uint(($2).z), $3, $4)\";\n")
3927
0
SLANG_RAW("        }\n")
3928
0
SLANG_RAW("        // Tv gather_compare(sampler s, float2 coord, float compare_value, int2 offset = int2(0)) const\n")
3929
0
SLANG_RAW("        __intrinsic_asm \"$0.gather_compare($1, $2, $3, $4)\";\n")
3930
0
SLANG_RAW("    case spirv:\n")
3931
0
SLANG_RAW("        return spirv_asm {\n")
3932
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
3933
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather %sampledImage $location $compareValue ConstOffset $offset;\n")
3934
0
SLANG_RAW("        };\n")
3935
0
SLANG_RAW("    case wgsl:\n")
3936
0
SLANG_RAW("        __wgsl_check_texture_type_texel_offset<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
3937
0
SLANG_RAW("        static_assert(Shape.flavor == ")
3938
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3939
0
)
3940
0
SLANG_RAW("\n")
3941
0
SLANG_RAW("            , \"WGSL texture gather with offset is supported only on 2D textures\");\n")
3942
0
SLANG_RAW("\n")
3943
0
SLANG_RAW("        if (isArray == 1)\n")
3944
0
SLANG_RAW("        {\n")
3945
0
SLANG_RAW("            switch (Shape.flavor)\n")
3946
0
SLANG_RAW("            {\n")
3947
0
SLANG_RAW("            case ")
3948
0
SLANG_SPLICE(SLANG_TEXTURE_2D
3949
0
)
3950
0
SLANG_RAW(":\n")
3951
0
SLANG_RAW("                __intrinsic_asm \"textureGatherCompare($0, $1, ($2).xy, u32(($2).z), $3, $4)\";\n")
3952
0
SLANG_RAW("            default:\n")
3953
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
3954
0
SLANG_RAW("            }\n")
3955
0
SLANG_RAW("        }\n")
3956
0
SLANG_RAW("        __intrinsic_asm \"textureGatherCompare($0, $1, $2, $3, $4)\";\n")
3957
0
SLANG_RAW("    }\n")
3958
0
SLANG_RAW("}\n")
3959
0
SLANG_RAW("\n")
3960
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3961
0
SLANG_RAW("[ForceInline]\n")
3962
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3963
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp_offset(\n")
3964
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
3965
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3966
0
SLANG_RAW("    T.Element compareValue,\n")
3967
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset)\n")
3968
0
SLANG_RAW("{\n")
3969
0
SLANG_RAW("    __target_switch\n")
3970
0
SLANG_RAW("    {\n")
3971
0
SLANG_RAW("    case glsl:\n")
3972
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffset($0, $1, $2, $3)\";\n")
3973
0
SLANG_RAW("    case spirv:\n")
3974
0
SLANG_RAW("        return spirv_asm {\n")
3975
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather $sampler $location $compareValue ConstOffset $offset;\n")
3976
0
SLANG_RAW("        };\n")
3977
0
SLANG_RAW("    }\n")
3978
0
SLANG_RAW("}\n")
3979
0
SLANG_RAW("\n")
3980
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
3981
0
SLANG_RAW("[ForceInline]\n")
3982
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
3983
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp_offsets(\n")
3984
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 0, format> texture,\n")
3985
0
SLANG_RAW("    SamplerComparisonState s,\n")
3986
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
3987
0
SLANG_RAW("    T.Element compareValue,\n")
3988
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset1,\n")
3989
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset2,\n")
3990
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset3,\n")
3991
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset4)\n")
3992
0
SLANG_RAW("{\n")
3993
0
SLANG_RAW("    __target_switch\n")
3994
0
SLANG_RAW("    {\n")
3995
0
SLANG_RAW("    case glsl:\n")
3996
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffsets($p, $2, $3, $T4[]($4, $5, $6, $7))\";\n")
3997
0
SLANG_RAW("    case spirv:\n")
3998
0
SLANG_RAW("        let offsets = __makeArray(offset1,offset2,offset3,offset4);\n")
3999
0
SLANG_RAW("        return spirv_asm {\n")
4000
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
4001
0
SLANG_RAW("            %sampledImage : __sampledImageType(texture) = OpSampledImage $texture $s;\n")
4002
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather %sampledImage $location $compareValue ConstOffsets $offsets;\n")
4003
0
SLANG_RAW("        };\n")
4004
0
SLANG_RAW("    }\n")
4005
0
SLANG_RAW("}\n")
4006
0
SLANG_RAW("\n")
4007
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let access:int, let isShadow:int, let format:int>\n")
4008
0
SLANG_RAW("[ForceInline]\n")
4009
0
SLANG_RAW("[require(glsl_spirv, texture_gather)]\n")
4010
0
SLANG_RAW("vector<T.Element,4> __texture_gatherCmp_offsets(\n")
4011
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0, sampleCount, access, isShadow, 1, format> sampler,\n")
4012
0
SLANG_RAW("    vector<float, Shape.dimensions+isArray> location,\n")
4013
0
SLANG_RAW("    T.Element compareValue,\n")
4014
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset1,\n")
4015
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset2,\n")
4016
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset3,\n")
4017
0
SLANG_RAW("    vector<int, Shape.planeDimensions> offset4)\n")
4018
0
SLANG_RAW("{\n")
4019
0
SLANG_RAW("    __target_switch\n")
4020
0
SLANG_RAW("    {\n")
4021
0
SLANG_RAW("    case glsl:\n")
4022
0
SLANG_RAW("        __intrinsic_asm \"textureGatherOffsets($0, $1, $2, $T3[]($3, $4, $5, $6))\";\n")
4023
0
SLANG_RAW("    case spirv:\n")
4024
0
SLANG_RAW("        let offsets = __makeArray(offset1,offset2,offset3,offset4);\n")
4025
0
SLANG_RAW("        return spirv_asm {\n")
4026
0
SLANG_RAW("            OpCapability ImageGatherExtended;\n")
4027
0
SLANG_RAW("            result:$$vector<T.Element,4> = OpImageDrefGather $sampler $location $compareValue ConstOffsets $offsets;\n")
4028
0
SLANG_RAW("        };\n")
4029
0
SLANG_RAW("    }\n")
4030
0
SLANG_RAW("}\n")
4031
0
SLANG_RAW("\n")
4032
4033
0
for (int isCombined = 0; isCombined < 2; isCombined++)
4034
0
{
4035
0
SLANG_RAW("#line 3519 \"hlsl.meta.slang\"")
4036
0
SLANG_RAW("\n")
4037
0
SLANG_RAW("// Gather for [isCombined = ")
4038
0
SLANG_SPLICE(isCombined
4039
0
)
4040
0
SLANG_RAW("]\n")
4041
0
SLANG_RAW("\n")
4042
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let isShadow:int, let format:int>\n")
4043
0
SLANG_RAW("extension _Texture<T,Shape,isArray,0,sampleCount,0,isShadow,")
4044
0
SLANG_SPLICE(isCombined
4045
0
)
4046
0
SLANG_RAW(",format>\n")
4047
0
SLANG_RAW("{\n")
4048
4049
0
    for (int isShadow = 0; isShadow < 2; isShadow++)
4050
0
    for (auto componentId = 0;  componentId < 5; componentId++)
4051
0
    {
4052
0
        const char* compareFunc = isShadow ? "Cmp" : "";
4053
0
        const char* compareParam = isShadow ? ", T.Element compareValue" : "";
4054
0
        const char* compareArg = isShadow ? ", compareValue" : "";
4055
4056
        // Some targets support the combined texture natively
4057
0
        const char* samplerParam = isCombined ? "" : (isShadow ? "SamplerComparisonState s," : "SamplerState s,");
4058
0
        const char* samplerArg = isCombined ? "" : ", s";
4059
0
        const char* getTexture = isCombined ? "__getTexture()" : "this";
4060
0
        const char* getSampler = isCombined ? (isShadow ? ", __getComparisonSampler()" : ", __getSampler()") : samplerArg;
4061
4062
0
        const char* componentFuncString[] = { "", "Red", "Green", "Blue", "Alpha"};
4063
0
        const char* componentArgString[] = { ", 0", ", 0", ", 1", ", 2", ", 3" };
4064
0
        const char* componentFunc = componentFuncString[componentId];
4065
0
        const char* componentArg = (isShadow ? "" : componentArgString[componentId]);
4066
0
SLANG_RAW("#line 3543 \"hlsl.meta.slang\"")
4067
0
SLANG_RAW("\n")
4068
0
SLANG_RAW("    [ForceInline]\n")
4069
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv_wgsl, texture_gather)]\n")
4070
0
SLANG_RAW("    vector<T.Element,4> Gather")
4071
0
SLANG_SPLICE(compareFunc
4072
0
)
4073
0
SLANG_SPLICE(componentFunc
4074
0
)
4075
0
SLANG_RAW("(\n")
4076
0
SLANG_RAW("        ")
4077
0
SLANG_SPLICE(samplerParam
4078
0
)
4079
0
SLANG_RAW("\n")
4080
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4081
0
SLANG_RAW("        ")
4082
0
SLANG_SPLICE(compareParam
4083
0
)
4084
0
SLANG_RAW(")\n")
4085
0
SLANG_RAW("    {\n")
4086
0
SLANG_RAW("        __target_switch\n")
4087
0
SLANG_RAW("        {\n")
4088
0
SLANG_RAW("        case hlsl:\n")
4089
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4090
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4091
0
)
4092
0
SLANG_RAW(" || Shape.flavor == ")
4093
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4094
0
)
4095
0
SLANG_RAW(",\n")
4096
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4097
0
SLANG_RAW("            __intrinsic_asm \".Gather")
4098
0
SLANG_SPLICE(compareFunc
4099
0
)
4100
0
SLANG_SPLICE(componentFunc
4101
0
)
4102
0
SLANG_RAW("\";\n")
4103
0
SLANG_RAW("        case cuda:\n")
4104
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4105
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4106
0
)
4107
0
SLANG_RAW(", \"CUDA Gather is supported only for 2D textures\");\n")
4108
0
SLANG_RAW("            static_assert(isArray == 0, \"CUDA Gather does not support texture arrays\");\n")
4109
0
SLANG_RAW("            __intrinsic_asm \"tex2Dgather<$T0>($0, ($2).x, ($2).y")
4110
0
SLANG_SPLICE(componentArg
4111
0
)
4112
0
SLANG_RAW(")\";\n")
4113
0
SLANG_RAW("        case metal:\n")
4114
0
SLANG_RAW("        case wgsl:\n")
4115
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4116
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4117
0
)
4118
0
SLANG_RAW(" || Shape.flavor == ")
4119
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4120
0
)
4121
0
SLANG_RAW(",\n")
4122
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4123
0
SLANG_RAW("            return __texture_gather")
4124
0
SLANG_SPLICE(compareFunc
4125
0
)
4126
0
SLANG_RAW("(")
4127
0
SLANG_SPLICE(getTexture
4128
0
)
4129
0
SLANG_RAW(" ")
4130
0
SLANG_SPLICE(getSampler
4131
0
)
4132
0
SLANG_RAW(", location ")
4133
0
SLANG_SPLICE(compareArg
4134
0
)
4135
0
SLANG_RAW(" ")
4136
0
SLANG_SPLICE(componentArg
4137
0
)
4138
0
SLANG_RAW(");\n")
4139
0
SLANG_RAW("        case glsl:\n")
4140
0
SLANG_RAW("        case spirv:\n")
4141
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4142
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4143
0
)
4144
0
SLANG_RAW(" || Shape.flavor == ")
4145
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4146
0
)
4147
0
SLANG_RAW(",\n")
4148
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4149
0
SLANG_RAW("            return __texture_gather")
4150
0
SLANG_SPLICE(compareFunc
4151
0
)
4152
0
SLANG_RAW("(this ")
4153
0
SLANG_SPLICE(samplerArg
4154
0
)
4155
0
SLANG_RAW(", location ")
4156
0
SLANG_SPLICE(compareArg
4157
0
)
4158
0
SLANG_RAW(" ")
4159
0
SLANG_SPLICE(componentArg
4160
0
)
4161
0
SLANG_RAW(");\n")
4162
0
SLANG_RAW("        }\n")
4163
0
SLANG_RAW("    }\n")
4164
0
SLANG_RAW("\n")
4165
0
SLANG_RAW("    [ForceInline]\n")
4166
0
SLANG_RAW("    [require(hlsl, texture_gather)]\n")
4167
0
SLANG_RAW("    vector<T.Element,4> Gather")
4168
0
SLANG_SPLICE(compareFunc
4169
0
)
4170
0
SLANG_SPLICE(componentFunc
4171
0
)
4172
0
SLANG_RAW("(\n")
4173
0
SLANG_RAW("        ")
4174
0
SLANG_SPLICE(samplerParam
4175
0
)
4176
0
SLANG_RAW("\n")
4177
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4178
0
SLANG_RAW("        ")
4179
0
SLANG_SPLICE(compareParam
4180
0
)
4181
0
SLANG_RAW(",\n")
4182
0
SLANG_RAW("        out uint status)\n")
4183
0
SLANG_RAW("    {\n")
4184
0
SLANG_RAW("        static_assert(Shape.flavor == ")
4185
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4186
0
)
4187
0
SLANG_RAW(" || Shape.flavor == ")
4188
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4189
0
)
4190
0
SLANG_RAW(",\n")
4191
0
SLANG_RAW("            \"Gather is supported only for 2D and 3D textures\");\n")
4192
0
SLANG_RAW("\n")
4193
0
SLANG_RAW("        __target_switch\n")
4194
0
SLANG_RAW("        {\n")
4195
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Gather")
4196
0
SLANG_SPLICE(compareFunc
4197
0
)
4198
0
SLANG_SPLICE(componentFunc
4199
0
)
4200
0
SLANG_RAW("\";\n")
4201
0
SLANG_RAW("        }\n")
4202
0
SLANG_RAW("    }\n")
4203
0
SLANG_RAW("\n")
4204
0
SLANG_RAW("    [ForceInline]\n")
4205
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv_wgsl, texture_gather)]\n")
4206
0
SLANG_RAW("    vector<T.Element,4> Gather")
4207
0
SLANG_SPLICE(compareFunc
4208
0
)
4209
0
SLANG_SPLICE(componentFunc
4210
0
)
4211
0
SLANG_RAW("(\n")
4212
0
SLANG_RAW("        ")
4213
0
SLANG_SPLICE(samplerParam
4214
0
)
4215
0
SLANG_RAW("\n")
4216
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4217
0
SLANG_RAW("        ")
4218
0
SLANG_SPLICE(compareParam
4219
0
)
4220
0
SLANG_RAW(",\n")
4221
0
SLANG_RAW("        vector<int, Shape.planeDimensions> offset)\n")
4222
0
SLANG_RAW("    {\n")
4223
0
SLANG_RAW("        __target_switch\n")
4224
0
SLANG_RAW("        {\n")
4225
0
SLANG_RAW("        case hlsl:\n")
4226
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4227
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4228
0
)
4229
0
SLANG_RAW(" || Shape.flavor == ")
4230
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4231
0
)
4232
0
SLANG_RAW(",\n")
4233
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4234
0
SLANG_RAW("            __intrinsic_asm \".Gather")
4235
0
SLANG_SPLICE(compareFunc
4236
0
)
4237
0
SLANG_SPLICE(componentFunc
4238
0
)
4239
0
SLANG_RAW("\";\n")
4240
0
SLANG_RAW("        case cuda:\n")
4241
0
SLANG_RAW("            // CUDA tex2Dgather doesn't support offset - ignore offset parameter\n")
4242
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4243
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4244
0
)
4245
0
SLANG_RAW(", \"CUDA Gather is supported only for 2D textures\");\n")
4246
0
SLANG_RAW("            static_assert(isArray == 0, \"CUDA Gather does not support texture arrays\");\n")
4247
0
SLANG_RAW("            __intrinsic_asm \"tex2Dgather<$T0>($0, ($2).x, ($2).y")
4248
0
SLANG_SPLICE(componentArg
4249
0
)
4250
0
SLANG_RAW(")\";\n")
4251
0
SLANG_RAW("        case metal:\n")
4252
0
SLANG_RAW("        case wgsl:\n")
4253
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4254
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4255
0
)
4256
0
SLANG_RAW(" || Shape.flavor == ")
4257
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4258
0
)
4259
0
SLANG_RAW(",\n")
4260
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4261
0
SLANG_RAW("            return __texture_gather")
4262
0
SLANG_SPLICE(compareFunc
4263
0
)
4264
0
SLANG_RAW("_offset(")
4265
0
SLANG_SPLICE(getTexture
4266
0
)
4267
0
SLANG_RAW(" ")
4268
0
SLANG_SPLICE(getSampler
4269
0
)
4270
0
SLANG_RAW(", location ")
4271
0
SLANG_SPLICE(compareArg
4272
0
)
4273
0
SLANG_RAW(", offset ")
4274
0
SLANG_SPLICE(componentArg
4275
0
)
4276
0
SLANG_RAW(");\n")
4277
0
SLANG_RAW("        case glsl:\n")
4278
0
SLANG_RAW("        case spirv:\n")
4279
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4280
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4281
0
)
4282
0
SLANG_RAW(" || Shape.flavor == ")
4283
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4284
0
)
4285
0
SLANG_RAW(",\n")
4286
0
SLANG_RAW("                \"Gather is supported only for 2D and 3D textures\");\n")
4287
0
SLANG_RAW("            return __texture_gather")
4288
0
SLANG_SPLICE(compareFunc
4289
0
)
4290
0
SLANG_RAW("_offset(this ")
4291
0
SLANG_SPLICE(samplerArg
4292
0
)
4293
0
SLANG_RAW(", location ")
4294
0
SLANG_SPLICE(compareArg
4295
0
)
4296
0
SLANG_RAW(", offset ")
4297
0
SLANG_SPLICE(componentArg
4298
0
)
4299
0
SLANG_RAW(");\n")
4300
0
SLANG_RAW("        }\n")
4301
0
SLANG_RAW("    }\n")
4302
0
SLANG_RAW("\n")
4303
0
SLANG_RAW("\n")
4304
0
SLANG_RAW("    [ForceInline]\n")
4305
0
SLANG_RAW("    [require(hlsl, texture_gather)]\n")
4306
0
SLANG_RAW("    vector<T.Element,4> Gather")
4307
0
SLANG_SPLICE(compareFunc
4308
0
)
4309
0
SLANG_SPLICE(componentFunc
4310
0
)
4311
0
SLANG_RAW("(\n")
4312
0
SLANG_RAW("        ")
4313
0
SLANG_SPLICE(samplerParam
4314
0
)
4315
0
SLANG_RAW("\n")
4316
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4317
0
SLANG_RAW("        ")
4318
0
SLANG_SPLICE(compareParam
4319
0
)
4320
0
SLANG_RAW(",\n")
4321
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset,\n")
4322
0
SLANG_RAW("        out uint status)\n")
4323
0
SLANG_RAW("    {\n")
4324
0
SLANG_RAW("        static_assert(Shape.flavor == ")
4325
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4326
0
)
4327
0
SLANG_RAW(" || Shape.flavor == ")
4328
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4329
0
)
4330
0
SLANG_RAW(",\n")
4331
0
SLANG_RAW("            \"Gather is supported only for 2D and 3D textures\");\n")
4332
0
SLANG_RAW("\n")
4333
0
SLANG_RAW("        __target_switch\n")
4334
0
SLANG_RAW("        {\n")
4335
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Gather")
4336
0
SLANG_SPLICE(compareFunc
4337
0
)
4338
0
SLANG_SPLICE(componentFunc
4339
0
)
4340
0
SLANG_RAW("\";\n")
4341
0
SLANG_RAW("        }\n")
4342
0
SLANG_RAW("    }\n")
4343
0
SLANG_RAW("\n")
4344
0
SLANG_RAW("    [ForceInline]\n")
4345
0
SLANG_RAW("    [require(glsl_hlsl_spirv, texture_gather)]\n")
4346
0
SLANG_RAW("    vector<T.Element,4> Gather")
4347
0
SLANG_SPLICE(compareFunc
4348
0
)
4349
0
SLANG_SPLICE(componentFunc
4350
0
)
4351
0
SLANG_RAW("(\n")
4352
0
SLANG_RAW("        ")
4353
0
SLANG_SPLICE(samplerParam
4354
0
)
4355
0
SLANG_RAW("\n")
4356
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4357
0
SLANG_RAW("        ")
4358
0
SLANG_SPLICE(compareParam
4359
0
)
4360
0
SLANG_RAW(",\n")
4361
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset1,\n")
4362
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset2,\n")
4363
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset3,\n")
4364
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset4)\n")
4365
0
SLANG_RAW("    {\n")
4366
0
SLANG_RAW("        static_assert(Shape.flavor == ")
4367
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4368
0
)
4369
0
SLANG_RAW(" || Shape.flavor == ")
4370
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4371
0
)
4372
0
SLANG_RAW(",\n")
4373
0
SLANG_RAW("            \"Gather is supported only for 2D and 3D textures\");\n")
4374
0
SLANG_RAW("\n")
4375
0
SLANG_RAW("        __target_switch\n")
4376
0
SLANG_RAW("        {\n")
4377
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Gather")
4378
0
SLANG_SPLICE(compareFunc
4379
0
)
4380
0
SLANG_SPLICE(componentFunc
4381
0
)
4382
0
SLANG_RAW("\";\n")
4383
0
SLANG_RAW("        case glsl:\n")
4384
0
SLANG_RAW("        case spirv:\n")
4385
0
SLANG_RAW("            return __texture_gather")
4386
0
SLANG_SPLICE(compareFunc
4387
0
)
4388
0
SLANG_RAW("_offsets<T>(this ")
4389
0
SLANG_SPLICE(samplerArg
4390
0
)
4391
0
SLANG_RAW(", location ")
4392
0
SLANG_SPLICE(compareArg
4393
0
)
4394
0
SLANG_RAW(", offset1,offset2,offset3,offset4 ")
4395
0
SLANG_SPLICE(componentArg
4396
0
)
4397
0
SLANG_RAW(");\n")
4398
0
SLANG_RAW("        }\n")
4399
0
SLANG_RAW("    }\n")
4400
0
SLANG_RAW("\n")
4401
0
SLANG_RAW("    [ForceInline]\n")
4402
0
SLANG_RAW("    [require(hlsl, texture_gather)]\n")
4403
0
SLANG_RAW("    vector<T.Element,4> Gather")
4404
0
SLANG_SPLICE(compareFunc
4405
0
)
4406
0
SLANG_SPLICE(componentFunc
4407
0
)
4408
0
SLANG_RAW("(\n")
4409
0
SLANG_RAW("        ")
4410
0
SLANG_SPLICE(samplerParam
4411
0
)
4412
0
SLANG_RAW("\n")
4413
0
SLANG_RAW("        vector<float, Shape.dimensions+isArray> location\n")
4414
0
SLANG_RAW("        ")
4415
0
SLANG_SPLICE(compareParam
4416
0
)
4417
0
SLANG_RAW(",\n")
4418
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset1,\n")
4419
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset2,\n")
4420
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset3,\n")
4421
0
SLANG_RAW("        constexpr vector<int, Shape.planeDimensions> offset4,\n")
4422
0
SLANG_RAW("        out uint status)\n")
4423
0
SLANG_RAW("    {\n")
4424
0
SLANG_RAW("        static_assert(Shape.flavor == ")
4425
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4426
0
)
4427
0
SLANG_RAW(" || Shape.flavor == ")
4428
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4429
0
)
4430
0
SLANG_RAW(",\n")
4431
0
SLANG_RAW("            \"Gather is supported only for 2D and 3D textures\");\n")
4432
0
SLANG_RAW("\n")
4433
0
SLANG_RAW("        __target_switch\n")
4434
0
SLANG_RAW("        {\n")
4435
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Gather")
4436
0
SLANG_SPLICE(compareFunc
4437
0
)
4438
0
SLANG_SPLICE(componentFunc
4439
0
)
4440
0
SLANG_RAW("\";\n")
4441
0
SLANG_RAW("        }\n")
4442
0
SLANG_RAW("    }\n")
4443
0
SLANG_RAW("\n")
4444
4445
0
    } // for (componentId)
4446
0
SLANG_RAW("#line 3688 \"hlsl.meta.slang\"")
4447
0
SLANG_RAW("\n")
4448
0
SLANG_RAW("} // End of: Gather for [isCombined = ")
4449
0
SLANG_SPLICE(isCombined
4450
0
)
4451
0
SLANG_RAW("]\n")
4452
0
SLANG_RAW("\n")
4453
4454
0
} // for (isScalarTexture)
4455
0
SLANG_RAW("#line 3693 \"hlsl.meta.slang\"")
4456
0
SLANG_RAW("\n")
4457
0
SLANG_RAW("\n")
4458
0
SLANG_RAW("// End of all Texture Gather\n")
4459
0
SLANG_RAW("\n")
4460
0
SLANG_RAW("\n")
4461
0
SLANG_RAW("// Load/Subscript for readonly, no MS textures\n")
4462
0
SLANG_RAW("\n")
4463
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let isShadow:int, let isCombined:int, let format:int>\n")
4464
0
SLANG_RAW("extension _Texture<T,Shape,isArray,0,sampleCount,0,isShadow,isCombined,format>\n")
4465
0
SLANG_RAW("{\n")
4466
0
SLANG_RAW("//@hidden:\n")
4467
0
SLANG_RAW("    static const int isMS = 0;\n")
4468
0
SLANG_RAW("    static const int access = ")
4469
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadOnly
4470
0
)
4471
0
SLANG_RAW(";\n")
4472
0
SLANG_RAW("//@public:\n")
4473
0
SLANG_RAW("    [__readNone]\n")
4474
0
SLANG_RAW("    [ForceInline]\n")
4475
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
4476
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray+1> location)\n")
4477
0
SLANG_RAW("    {\n")
4478
0
SLANG_RAW("        __target_switch\n")
4479
0
SLANG_RAW("        {\n")
4480
0
SLANG_RAW("        case cpp:\n")
4481
0
SLANG_RAW("        case hlsl:\n")
4482
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
4483
0
SLANG_RAW("\t\tcase cuda:\n")
4484
0
SLANG_RAW("            if (isArray != 0)\n")
4485
0
SLANG_RAW("            {\n")
4486
0
SLANG_RAW("                switch(Shape.flavor)\n")
4487
0
SLANG_RAW("                {\n")
4488
0
SLANG_RAW("                case ")
4489
0
SLANG_SPLICE(SLANG_TEXTURE_1D
4490
0
)
4491
0
SLANG_RAW(":\n")
4492
0
SLANG_RAW("                    __intrinsic_asm \"tex1DArrayfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)\";\n")
4493
0
SLANG_RAW("                case ")
4494
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4495
0
)
4496
0
SLANG_RAW(":\n")
4497
0
SLANG_RAW("                    __intrinsic_asm \"tex2DArrayfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z, ($1).w)\";\n")
4498
0
SLANG_RAW("                }\n")
4499
0
SLANG_RAW("            }\n")
4500
0
SLANG_RAW("            else\n")
4501
0
SLANG_RAW("            {\n")
4502
0
SLANG_RAW("                switch(Shape.flavor)\n")
4503
0
SLANG_RAW("                {\n")
4504
0
SLANG_RAW("                case ")
4505
0
SLANG_SPLICE(SLANG_TEXTURE_1D
4506
0
)
4507
0
SLANG_RAW(":\n")
4508
0
SLANG_RAW("                    __intrinsic_asm \"tex1Dfetch_int<$T0>($0, ($1).x, ($1).y)\";\n")
4509
0
SLANG_RAW("                case ")
4510
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4511
0
)
4512
0
SLANG_RAW(":\n")
4513
0
SLANG_RAW("                    __intrinsic_asm \"tex2Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)\";\n")
4514
0
SLANG_RAW("                case ")
4515
0
SLANG_SPLICE(SLANG_TEXTURE_3D
4516
0
)
4517
0
SLANG_RAW(":\n")
4518
0
SLANG_RAW("                    __intrinsic_asm \"tex3Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z, ($1).w)\";\n")
4519
0
SLANG_RAW("                }\n")
4520
0
SLANG_RAW("            }\n")
4521
0
SLANG_RAW("            static_assert(false, \"Unsupported 'Load' of 'texture' for 'cuda' target\");\n")
4522
0
SLANG_RAW("            __intrinsic_asm \"<invalid intrinsic>\";\n")
4523
0
SLANG_RAW("        case metal:\n")
4524
0
SLANG_RAW("            switch (Shape.flavor)\n")
4525
0
SLANG_RAW("            {\n")
4526
0
SLANG_RAW("            case ")
4527
0
SLANG_SPLICE(SLANG_TEXTURE_1D
4528
0
)
4529
0
SLANG_RAW(":\n")
4530
0
SLANG_RAW("                // lod is not supported for 1D texture\n")
4531
0
SLANG_RAW("                if (isArray == 1)\n")
4532
0
SLANG_RAW("                    // Tv read(uint coord, uint array, uint lod = 0) const\n")
4533
0
SLANG_RAW("                    __intrinsic_asm \"$c$0.read(uint(($1).x), uint(($1).y))$z\";\n")
4534
0
SLANG_RAW("                else\n")
4535
0
SLANG_RAW("                    // Tv read(uint coord, uint lod = 0) const\n")
4536
0
SLANG_RAW("                    __intrinsic_asm \"$c$0.read(uint(($1).x))$z\";\n")
4537
0
SLANG_RAW("                break;\n")
4538
0
SLANG_RAW("            case ")
4539
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4540
0
)
4541
0
SLANG_RAW(":\n")
4542
0
SLANG_RAW("                if (isShadow == 1)\n")
4543
0
SLANG_RAW("                {\n")
4544
0
SLANG_RAW("                    if (isArray == 1)\n")
4545
0
SLANG_RAW("                        // T read(uint2 coord, uint array, uint lod = 0) const\n")
4546
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
4547
0
SLANG_RAW("                    else\n")
4548
0
SLANG_RAW("                        // T read(uint2 coord, uint lod = 0) const\n")
4549
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z))$z\";\n")
4550
0
SLANG_RAW("                }\n")
4551
0
SLANG_RAW("                else\n")
4552
0
SLANG_RAW("                {\n")
4553
0
SLANG_RAW("                    if (isArray == 1)\n")
4554
0
SLANG_RAW("                        // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
4555
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
4556
0
SLANG_RAW("                    else\n")
4557
0
SLANG_RAW("                        // Tv read(uint2 coord, uint lod = 0) const\n")
4558
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z))$z\";\n")
4559
0
SLANG_RAW("                }\n")
4560
0
SLANG_RAW("                break;\n")
4561
0
SLANG_RAW("            case ")
4562
0
SLANG_SPLICE(SLANG_TEXTURE_3D
4563
0
)
4564
0
SLANG_RAW(":\n")
4565
0
SLANG_RAW("                if (isShadow == 0 && isArray == 0)\n")
4566
0
SLANG_RAW("                    // Tv read(uint3 coord, uint lod = 0) const\n")
4567
0
SLANG_RAW("                    __intrinsic_asm \"$c$0.read(vec<uint,3>(($1).xyz), uint(($1).w))$z\";\n")
4568
0
SLANG_RAW("                break;\n")
4569
0
SLANG_RAW("            case ")
4570
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
4571
0
)
4572
0
SLANG_RAW(":\n")
4573
0
SLANG_RAW("                static_assert(isArray == 0, \"Unsupported 'Load' of 'texture cube array' for 'metal' target\");\n")
4574
0
SLANG_RAW("                if (isShadow == 1)\n")
4575
0
SLANG_RAW("                {\n")
4576
0
SLANG_RAW("                    if (isArray == 1)\n")
4577
0
SLANG_RAW("                        // T read(uint2 coord, uint face, uint array, uint lod = 0) const\n")
4578
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsics>\";\n")
4579
0
SLANG_RAW("                    else\n")
4580
0
SLANG_RAW("                        // T read(uint2 coord, uint face, uint lod = 0) const\n")
4581
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
4582
0
SLANG_RAW("                }\n")
4583
0
SLANG_RAW("                else\n")
4584
0
SLANG_RAW("                {\n")
4585
0
SLANG_RAW("                    if (isArray == 1)\n")
4586
0
SLANG_RAW("                        // Tv read(uint2 coord, uint face, uint array, uint lod = 0) const\n")
4587
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsics>\";\n")
4588
0
SLANG_RAW("                    else\n")
4589
0
SLANG_RAW("                        // Tv read(uint2 coord, uint face, uint lod = 0) const\n")
4590
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
4591
0
SLANG_RAW("                }\n")
4592
0
SLANG_RAW("                break;\n")
4593
0
SLANG_RAW("            }\n")
4594
0
SLANG_RAW("            static_assert(false, \"Unsupported 'Load' of 'texture' for 'metal' target\");\n")
4595
0
SLANG_RAW("            __intrinsic_asm \"<invalid intrinsics>\";\n")
4596
0
SLANG_RAW("        case glsl:\n")
4597
0
SLANG_RAW("            if (isCombined == 0)\n")
4598
0
SLANG_RAW("                __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4599
0
SLANG_RAW("            __intrinsic_asm \"$ctexelFetch($0, ($1).$w1b, ($1).$w1e)$z\";\n")
4600
0
SLANG_RAW("        case spirv:\n")
4601
0
SLANG_RAW("            const int lodLoc = Shape.dimensions+isArray;\n")
4602
0
SLANG_RAW("            let coord = __vectorReshape<Shape.dimensions+isArray>(location);\n")
4603
0
SLANG_RAW("            let lod = location[lodLoc];\n")
4604
0
SLANG_RAW("            if (isCombined != 0)\n")
4605
0
SLANG_RAW("            {\n")
4606
0
SLANG_RAW("                return spirv_asm\n")
4607
0
SLANG_RAW("                {\n")
4608
0
SLANG_RAW("                    %image:__imageType(this) = OpImage $this;\n")
4609
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageFetch %image $coord Lod $lod;\n")
4610
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
4611
0
SLANG_RAW("                };\n")
4612
0
SLANG_RAW("            }\n")
4613
0
SLANG_RAW("            else\n")
4614
0
SLANG_RAW("            {\n")
4615
0
SLANG_RAW("                return spirv_asm\n")
4616
0
SLANG_RAW("                {\n")
4617
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageFetch $this $coord Lod $lod;\n")
4618
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
4619
0
SLANG_RAW("                };\n")
4620
0
SLANG_RAW("            }\n")
4621
0
SLANG_RAW("        case wgsl:\n")
4622
0
SLANG_RAW("            __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
4623
0
SLANG_RAW("\n")
4624
0
SLANG_RAW("            static_assert(Shape.flavor == ")
4625
0
SLANG_SPLICE(SLANG_TEXTURE_1D
4626
0
)
4627
0
SLANG_RAW("\n")
4628
0
SLANG_RAW("                || Shape.flavor == ")
4629
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4630
0
)
4631
0
SLANG_RAW("\n")
4632
0
SLANG_RAW("                || Shape.flavor == ")
4633
0
SLANG_SPLICE(SLANG_TEXTURE_3D
4634
0
)
4635
0
SLANG_RAW("\n")
4636
0
SLANG_RAW("                , \"WGSL does not support textureLoad for Cube textures.\");\n")
4637
0
SLANG_RAW("\n")
4638
0
SLANG_RAW("            if (isArray == 1)\n")
4639
0
SLANG_RAW("            {\n")
4640
0
SLANG_RAW("                switch (Shape.flavor)\n")
4641
0
SLANG_RAW("                {\n")
4642
0
SLANG_RAW("                case ")
4643
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4644
0
)
4645
0
SLANG_RAW(":\n")
4646
0
SLANG_RAW("                    __intrinsic_asm \"textureLoad($0, ($1).xy, i32(($1).z), ($1).w)$z\";\n")
4647
0
SLANG_RAW("                }\n")
4648
0
SLANG_RAW("            }\n")
4649
0
SLANG_RAW("            switch (Shape.flavor)\n")
4650
0
SLANG_RAW("            {\n")
4651
0
SLANG_RAW("            case ")
4652
0
SLANG_SPLICE(SLANG_TEXTURE_1D
4653
0
)
4654
0
SLANG_RAW(":\n")
4655
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, ($1).x, ($1).y)$z\";\n")
4656
0
SLANG_RAW("            case ")
4657
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4658
0
)
4659
0
SLANG_RAW(":\n")
4660
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, ($1).xy, ($1).z)$z\";\n")
4661
0
SLANG_RAW("            case ")
4662
0
SLANG_SPLICE(SLANG_TEXTURE_3D
4663
0
)
4664
0
SLANG_RAW(":\n")
4665
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, ($1).xyz, ($1).w)$z\";\n")
4666
0
SLANG_RAW("            default:\n")
4667
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
4668
0
SLANG_RAW("            }\n")
4669
0
SLANG_RAW("            return __default<T>();\n")
4670
0
SLANG_RAW("        }\n")
4671
0
SLANG_RAW("    }\n")
4672
0
SLANG_RAW("\n")
4673
0
SLANG_RAW("    [__readNone]\n")
4674
0
SLANG_RAW("    [ForceInline]\n")
4675
0
SLANG_RAW("    [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_samplerless)]\n")
4676
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray+1> location, constexpr vector<int, Shape.planeDimensions> offset)\n")
4677
0
SLANG_RAW("    {\n")
4678
0
SLANG_RAW("        __target_switch\n")
4679
0
SLANG_RAW("        {\n")
4680
0
SLANG_RAW("            case cpp:\n")
4681
0
SLANG_RAW("            case hlsl:\n")
4682
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
4683
0
SLANG_RAW("            case glsl:\n")
4684
0
SLANG_RAW("                if (isCombined == 0)\n")
4685
0
SLANG_RAW("                    __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4686
0
SLANG_RAW("                __intrinsic_asm \"$ctexelFetchOffset($0, ($1).$w1b, ($1).$w1e, ($2))$z\";\n")
4687
0
SLANG_RAW("            case spirv:\n")
4688
0
SLANG_RAW("                const int lodLoc = Shape.dimensions+isArray;\n")
4689
0
SLANG_RAW("                let coord = __vectorReshape<Shape.dimensions+isArray>(location);\n")
4690
0
SLANG_RAW("                let lod = location[lodLoc];\n")
4691
0
SLANG_RAW("                if (isCombined != 0)\n")
4692
0
SLANG_RAW("                {\n")
4693
0
SLANG_RAW("                    return spirv_asm\n")
4694
0
SLANG_RAW("                    {\n")
4695
0
SLANG_RAW("                        %image:__imageType(this) = OpImage $this;\n")
4696
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch %image $coord Lod|ConstOffset $lod $offset;\n")
4697
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4698
0
SLANG_RAW("                    };\n")
4699
0
SLANG_RAW("                }\n")
4700
0
SLANG_RAW("                else\n")
4701
0
SLANG_RAW("                {\n")
4702
0
SLANG_RAW("                    return spirv_asm\n")
4703
0
SLANG_RAW("                    {\n")
4704
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch $this $coord Lod|ConstOffset $lod $offset;\n")
4705
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4706
0
SLANG_RAW("                    };\n")
4707
0
SLANG_RAW("                }\n")
4708
0
SLANG_RAW("        }\n")
4709
0
SLANG_RAW("    }\n")
4710
0
SLANG_RAW("\n")
4711
0
SLANG_RAW("    [__readNone]\n")
4712
0
SLANG_RAW("    [ForceInline]\n")
4713
0
SLANG_RAW("    [require(hlsl_spirv, texture_sm_4_1_samplerless)]\n")
4714
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray+1> location, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
4715
0
SLANG_RAW("    {\n")
4716
0
SLANG_RAW("        __target_switch\n")
4717
0
SLANG_RAW("        {\n")
4718
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
4719
0
SLANG_RAW("        case spirv:\n")
4720
0
SLANG_RAW("             const int lodLoc = Shape.dimensions+isArray;\n")
4721
0
SLANG_RAW("             let coord = __vectorReshape<Shape.dimensions+isArray>(location);\n")
4722
0
SLANG_RAW("             let lod = location[lodLoc];\n")
4723
0
SLANG_RAW("             if (isCombined != 0)\n")
4724
0
SLANG_RAW("             {\n")
4725
0
SLANG_RAW("                 return spirv_asm\n")
4726
0
SLANG_RAW("                 {\n")
4727
0
SLANG_RAW("                     OpCapability SparseResidency;\n")
4728
0
SLANG_RAW("                     %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
4729
0
SLANG_RAW("                     %image:__imageType(this) = OpImage $this;\n")
4730
0
SLANG_RAW("\n")
4731
0
SLANG_RAW("                     %sparseResult:%sparseResultType = OpImageSparseFetch %image $coord Lod|ConstOffset $lod $offset;\n")
4732
0
SLANG_RAW("                     %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
4733
0
SLANG_RAW("                     %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
4734
0
SLANG_RAW("\n")
4735
0
SLANG_RAW("                     OpStore &status %residentCode;\n")
4736
0
SLANG_RAW("                     __truncate $$T result __sampledType(T) %sampled;\n")
4737
0
SLANG_RAW("                 };\n")
4738
0
SLANG_RAW("             }\n")
4739
0
SLANG_RAW("             else\n")
4740
0
SLANG_RAW("             {\n")
4741
0
SLANG_RAW("                 return spirv_asm\n")
4742
0
SLANG_RAW("                 {\n")
4743
0
SLANG_RAW("                     OpCapability SparseResidency;\n")
4744
0
SLANG_RAW("                     %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
4745
0
SLANG_RAW("\n")
4746
0
SLANG_RAW("                     %sparseResult:%sparseResultType = OpImageSparseFetch $this $coord Lod|ConstOffset $lod $offset;\n")
4747
0
SLANG_RAW("                     %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
4748
0
SLANG_RAW("                     %sampled:__sampledType(T) = OpCompositeExtract  %sparseResult 1;\n")
4749
0
SLANG_RAW("\n")
4750
0
SLANG_RAW("                     OpStore &status %residentCode;\n")
4751
0
SLANG_RAW("                     __truncate $$T result __sampledType(T) %sampled;\n")
4752
0
SLANG_RAW("                 };\n")
4753
0
SLANG_RAW("             }\n")
4754
0
SLANG_RAW("        default:\n")
4755
0
SLANG_RAW("            status = 0;\n")
4756
0
SLANG_RAW("            return Load(location, offset);\n")
4757
0
SLANG_RAW("        }\n")
4758
0
SLANG_RAW("    }\n")
4759
0
SLANG_RAW("\n")
4760
0
SLANG_RAW("    __subscript(vector<uint, Shape.dimensions+isArray> location) -> T\n")
4761
0
SLANG_RAW("    {\n")
4762
0
SLANG_RAW("        [__readNone]\n")
4763
0
SLANG_RAW("        [ForceInline]\n")
4764
0
SLANG_RAW("        [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
4765
0
SLANG_RAW("        get\n")
4766
0
SLANG_RAW("        {\n")
4767
0
SLANG_RAW("            __target_switch\n")
4768
0
SLANG_RAW("            {\n")
4769
0
SLANG_RAW("                case cpp:\n")
4770
0
SLANG_RAW("                case hlsl:\n")
4771
0
SLANG_RAW("                    __intrinsic_asm \".operator[]\";\n")
4772
0
SLANG_RAW("                case metal:\n")
4773
0
SLANG_RAW("                case cuda:\n")
4774
0
SLANG_RAW("                    return Load(__makeVector(location, 0));\n")
4775
0
SLANG_RAW("                case glsl:\n")
4776
0
SLANG_RAW("                    if (isCombined == 0)\n")
4777
0
SLANG_RAW("                        __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4778
0
SLANG_RAW("\n")
4779
0
SLANG_RAW("                    return Load(__makeVector(location, 0));\n")
4780
0
SLANG_RAW("                case spirv:\n")
4781
0
SLANG_RAW("                    if (isCombined != 0)\n")
4782
0
SLANG_RAW("                    {\n")
4783
0
SLANG_RAW("                        return spirv_asm\n")
4784
0
SLANG_RAW("                        {\n")
4785
0
SLANG_RAW("                            %image:__imageType(this) = OpImage $this;\n")
4786
0
SLANG_RAW("                            %sampled:__sampledType(T) = OpImageFetch %image $location;\n")
4787
0
SLANG_RAW("                            __truncate $$T result __sampledType(T) %sampled;\n")
4788
0
SLANG_RAW("                        };\n")
4789
0
SLANG_RAW("                    }\n")
4790
0
SLANG_RAW("                    else\n")
4791
0
SLANG_RAW("                    {\n")
4792
0
SLANG_RAW("                        return spirv_asm\n")
4793
0
SLANG_RAW("                        {\n")
4794
0
SLANG_RAW("                            %sampled:__sampledType(T) = OpImageFetch $this $location;\n")
4795
0
SLANG_RAW("                            __truncate $$T result __sampledType(T) %sampled;\n")
4796
0
SLANG_RAW("                        };\n")
4797
0
SLANG_RAW("                    }\n")
4798
0
SLANG_RAW("                case wgsl:\n")
4799
0
SLANG_RAW("                    return Load(__makeVector(location, 0));\n")
4800
0
SLANG_RAW("            }\n")
4801
0
SLANG_RAW("        }\n")
4802
0
SLANG_RAW("    }\n")
4803
0
SLANG_RAW("}\n")
4804
0
SLANG_RAW("\n")
4805
0
SLANG_RAW("// Texture Load/Subscript for readonly, MS textures\n")
4806
0
SLANG_RAW("\n")
4807
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let isShadow:int, let isCombined:int, let format:int>\n")
4808
0
SLANG_RAW("extension _Texture<T,Shape,isArray,1,sampleCount,0,isShadow,isCombined,format>\n")
4809
0
SLANG_RAW("{\n")
4810
0
SLANG_RAW("//@hidden:\n")
4811
0
SLANG_RAW("    static const int access = ")
4812
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadOnly
4813
0
)
4814
0
SLANG_RAW(";\n")
4815
0
SLANG_RAW("    static const int isMS = 1;\n")
4816
0
SLANG_RAW("//@public:\n")
4817
0
SLANG_RAW("    [__readNone]\n")
4818
0
SLANG_RAW("    [ForceInline]\n")
4819
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
4820
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex)\n")
4821
0
SLANG_RAW("    {\n")
4822
0
SLANG_RAW("        __target_switch\n")
4823
0
SLANG_RAW("        {\n")
4824
0
SLANG_RAW("            case cpp:\n")
4825
0
SLANG_RAW("            case hlsl:\n")
4826
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
4827
0
SLANG_RAW("            case metal:\n")
4828
0
SLANG_RAW("                switch (Shape.flavor)\n")
4829
0
SLANG_RAW("                {\n")
4830
0
SLANG_RAW("                case ")
4831
0
SLANG_SPLICE(SLANG_TEXTURE_2D
4832
0
)
4833
0
SLANG_RAW(":\n")
4834
0
SLANG_RAW("                    if (isShadow == 1)\n")
4835
0
SLANG_RAW("                    {\n")
4836
0
SLANG_RAW("                        if (isArray == 1)\n")
4837
0
SLANG_RAW("                            // Document seems to have a typo. `lod` must be `sample`.\n")
4838
0
SLANG_RAW("                            // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
4839
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(($1).xy, ($1).z, uint($2))$z\";\n")
4840
0
SLANG_RAW("                        else\n")
4841
0
SLANG_RAW("                            // T read(uint2 coord, uint sample) const\n")
4842
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read($1, uint($2))$z\";\n")
4843
0
SLANG_RAW("                    }\n")
4844
0
SLANG_RAW("                    else\n")
4845
0
SLANG_RAW("                    {\n")
4846
0
SLANG_RAW("                        if (isArray == 1)\n")
4847
0
SLANG_RAW("                            // Document seems to have a typo. `lod` must be `sample`.\n")
4848
0
SLANG_RAW("                            // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
4849
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(($1).xy, ($1).z, uint($2))$z\";\n")
4850
0
SLANG_RAW("                        else\n")
4851
0
SLANG_RAW("                            // Tv read(uint2 coord, uint sample) const\n")
4852
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read($1, uint($2))$z\";\n")
4853
0
SLANG_RAW("                    }\n")
4854
0
SLANG_RAW("                    break;\n")
4855
0
SLANG_RAW("                }\n")
4856
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
4857
0
SLANG_RAW("                __intrinsic_asm \"<Not supported>\";\n")
4858
0
SLANG_RAW("            case glsl:\n")
4859
0
SLANG_RAW("                if (isCombined == 0)\n")
4860
0
SLANG_RAW("                    __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4861
0
SLANG_RAW("                __intrinsic_asm \"$ctexelFetch($0, $1, ($2))$z\";\n")
4862
0
SLANG_RAW("            case spirv:\n")
4863
0
SLANG_RAW("                if (isCombined != 0)\n")
4864
0
SLANG_RAW("                {\n")
4865
0
SLANG_RAW("                    return spirv_asm\n")
4866
0
SLANG_RAW("                    {\n")
4867
0
SLANG_RAW("                        %image:__imageType(this) = OpImage $this;\n")
4868
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch %image $location Sample $sampleIndex;\n")
4869
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4870
0
SLANG_RAW("                    };\n")
4871
0
SLANG_RAW("                }\n")
4872
0
SLANG_RAW("                else\n")
4873
0
SLANG_RAW("                {\n")
4874
0
SLANG_RAW("                    return spirv_asm\n")
4875
0
SLANG_RAW("                    {\n")
4876
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch $this $location Sample $sampleIndex;\n")
4877
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4878
0
SLANG_RAW("                    };\n")
4879
0
SLANG_RAW("                }\n")
4880
0
SLANG_RAW("            case wgsl:\n")
4881
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format>();\n")
4882
0
SLANG_RAW("\n")
4883
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, $1, $2)$z\";\n")
4884
0
SLANG_RAW("        }\n")
4885
0
SLANG_RAW("    }\n")
4886
0
SLANG_RAW("\n")
4887
0
SLANG_RAW("    [__readNone]\n")
4888
0
SLANG_RAW("    [ForceInline]\n")
4889
0
SLANG_RAW("    [require(cpp_glsl_hlsl_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
4890
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions + isArray + 1> locationAndSampleIndex)\n")
4891
0
SLANG_RAW("    {\n")
4892
0
SLANG_RAW("        return Load(__vectorReshape<Shape.dimensions + isArray>(locationAndSampleIndex), locationAndSampleIndex[Shape.dimensions + isArray]);\n")
4893
0
SLANG_RAW("    }\n")
4894
0
SLANG_RAW("\n")
4895
0
SLANG_RAW("    [__readNone]\n")
4896
0
SLANG_RAW("    [ForceInline]\n")
4897
0
SLANG_RAW("    [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_samplerless)]\n")
4898
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex, constexpr vector<int, Shape.planeDimensions> offset)\n")
4899
0
SLANG_RAW("    {\n")
4900
0
SLANG_RAW("        __target_switch\n")
4901
0
SLANG_RAW("        {\n")
4902
0
SLANG_RAW("            case cpp:\n")
4903
0
SLANG_RAW("            case hlsl:\n")
4904
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
4905
0
SLANG_RAW("            case glsl:\n")
4906
0
SLANG_RAW("                if (isCombined == 0)\n")
4907
0
SLANG_RAW("                    __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4908
0
SLANG_RAW("                __intrinsic_asm \"$ctexelFetchOffset($0, $1, ($2), ($3))$z\";\n")
4909
0
SLANG_RAW("            case spirv:\n")
4910
0
SLANG_RAW("                if (isCombined != 0)\n")
4911
0
SLANG_RAW("                {\n")
4912
0
SLANG_RAW("                    return spirv_asm\n")
4913
0
SLANG_RAW("                    {\n")
4914
0
SLANG_RAW("                        %image:__imageType(this) = OpImage $this;\n")
4915
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch %image $location ConstOffset|Sample $offset $sampleIndex;\n")
4916
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4917
0
SLANG_RAW("                    };\n")
4918
0
SLANG_RAW("                }\n")
4919
0
SLANG_RAW("                else\n")
4920
0
SLANG_RAW("                {\n")
4921
0
SLANG_RAW("                    return spirv_asm\n")
4922
0
SLANG_RAW("                    {\n")
4923
0
SLANG_RAW("                        %sampled:__sampledType(T) = OpImageFetch $this $location ConstOffset|Sample $offset  $sampleIndex;\n")
4924
0
SLANG_RAW("                        __truncate $$T result __sampledType(T) %sampled;\n")
4925
0
SLANG_RAW("                    };\n")
4926
0
SLANG_RAW("                }\n")
4927
0
SLANG_RAW("        }\n")
4928
0
SLANG_RAW("    }\n")
4929
0
SLANG_RAW("\n")
4930
0
SLANG_RAW("    [__readNone]\n")
4931
0
SLANG_RAW("    [ForceInline]\n")
4932
0
SLANG_RAW("    [require(hlsl_spirv, texture_sm_4_1_samplerless)]\n")
4933
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex, constexpr vector<int, Shape.planeDimensions> offset, out uint status)\n")
4934
0
SLANG_RAW("    {\n")
4935
0
SLANG_RAW("        __target_switch\n")
4936
0
SLANG_RAW("        {\n")
4937
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
4938
0
SLANG_RAW("        case spirv:\n")
4939
0
SLANG_RAW("             if (isCombined != 0)\n")
4940
0
SLANG_RAW("             {\n")
4941
0
SLANG_RAW("                 return spirv_asm\n")
4942
0
SLANG_RAW("                 {\n")
4943
0
SLANG_RAW("                     OpCapability SparseResidency;\n")
4944
0
SLANG_RAW("                     %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
4945
0
SLANG_RAW("                     %image:__imageType(this) = OpImage $this;\n")
4946
0
SLANG_RAW("\n")
4947
0
SLANG_RAW("                     %sparseResult:%sparseResultType = OpImageSparseFetch %image $location ConstOffset|Sample $offset $sampleIndex;\n")
4948
0
SLANG_RAW("                     %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
4949
0
SLANG_RAW("                     %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
4950
0
SLANG_RAW("\n")
4951
0
SLANG_RAW("                     OpStore &status %residentCode;\n")
4952
0
SLANG_RAW("                     __truncate $$T result __sampledType(T) %sampled;\n")
4953
0
SLANG_RAW("                 };\n")
4954
0
SLANG_RAW("             }\n")
4955
0
SLANG_RAW("             else\n")
4956
0
SLANG_RAW("             {\n")
4957
0
SLANG_RAW("                 return spirv_asm\n")
4958
0
SLANG_RAW("                 {\n")
4959
0
SLANG_RAW("                     OpCapability SparseResidency;\n")
4960
0
SLANG_RAW("                     %sparseResultType = OpTypeStruct $$uint __sampledType(T);\n")
4961
0
SLANG_RAW("\n")
4962
0
SLANG_RAW("                     %sparseResult:%sparseResultType = OpImageSparseFetch $this $location ConstOffset|Sample $offset $sampleIndex;\n")
4963
0
SLANG_RAW("                     %residentCode:$$uint = OpCompositeExtract %sparseResult 0;\n")
4964
0
SLANG_RAW("                     %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;\n")
4965
0
SLANG_RAW("\n")
4966
0
SLANG_RAW("                     OpStore &status %residentCode;\n")
4967
0
SLANG_RAW("                     __truncate $$T result __sampledType(T) %sampled;\n")
4968
0
SLANG_RAW("                 };\n")
4969
0
SLANG_RAW("             }\n")
4970
0
SLANG_RAW("        default:\n")
4971
0
SLANG_RAW("            status = 0;\n")
4972
0
SLANG_RAW("            return Load(location, sampleIndex, offset);\n")
4973
0
SLANG_RAW("        }\n")
4974
0
SLANG_RAW("    }\n")
4975
0
SLANG_RAW("\n")
4976
0
SLANG_RAW("    __subscript(vector<uint, Shape.dimensions+isArray> location) -> T\n")
4977
0
SLANG_RAW("    {\n")
4978
0
SLANG_RAW("        [__readNone]\n")
4979
0
SLANG_RAW("        [ForceInline]\n")
4980
0
SLANG_RAW("        [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
4981
0
SLANG_RAW("        get\n")
4982
0
SLANG_RAW("        {\n")
4983
0
SLANG_RAW("            __target_switch\n")
4984
0
SLANG_RAW("            {\n")
4985
0
SLANG_RAW("                case cpp:\n")
4986
0
SLANG_RAW("                case hlsl:\n")
4987
0
SLANG_RAW("                    __intrinsic_asm \"($0).sample[$1]\";\n")
4988
0
SLANG_RAW("                case metal:\n")
4989
0
SLANG_RAW("                case spirv:\n")
4990
0
SLANG_RAW("                case wgsl:\n")
4991
0
SLANG_RAW("                    return Load(location, 0);\n")
4992
0
SLANG_RAW("                case glsl:\n")
4993
0
SLANG_RAW("                    if (isCombined == 0)\n")
4994
0
SLANG_RAW("                        __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
4995
0
SLANG_RAW("                    return Load(location, 0);\n")
4996
0
SLANG_RAW("            }\n")
4997
0
SLANG_RAW("        }\n")
4998
0
SLANG_RAW("    }\n")
4999
0
SLANG_RAW("    __subscript(vector<uint, Shape.dimensions+isArray> location, int sampleIndex) -> T\n")
5000
0
SLANG_RAW("    {\n")
5001
0
SLANG_RAW("        [__readNone]\n")
5002
0
SLANG_RAW("        [ForceInline]\n")
5003
0
SLANG_RAW("        [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_samplerless)]\n")
5004
0
SLANG_RAW("        get\n")
5005
0
SLANG_RAW("        {\n")
5006
0
SLANG_RAW("            __target_switch\n")
5007
0
SLANG_RAW("            {\n")
5008
0
SLANG_RAW("                case cpp:\n")
5009
0
SLANG_RAW("                case hlsl:\n")
5010
0
SLANG_RAW("                    __intrinsic_asm \"($0).sample[$2][$1]\";\n")
5011
0
SLANG_RAW("                case metal:\n")
5012
0
SLANG_RAW("                case spirv:\n")
5013
0
SLANG_RAW("                case wgsl:\n")
5014
0
SLANG_RAW("                    return Load(location, sampleIndex);\n")
5015
0
SLANG_RAW("                case glsl:\n")
5016
0
SLANG_RAW("                    if (isCombined == 0)\n")
5017
0
SLANG_RAW("                        __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
5018
0
SLANG_RAW("                    return Load(location, sampleIndex);\n")
5019
0
SLANG_RAW("            }\n")
5020
0
SLANG_RAW("        }\n")
5021
0
SLANG_RAW("    }\n")
5022
0
SLANG_RAW("}\n")
5023
0
SLANG_RAW("\n")
5024
0
SLANG_RAW("// Load/Subscript for readwrite textures\n")
5025
5026
0
    for (int access = kCoreModule_ResourceAccessReadWrite; access <= kCoreModule_ResourceAccessRasterizerOrdered; access++) {
5027
0
        const char* glslIntrinsic = "$cimageLoad($0, $1)$z";
5028
0
        const char* glslIntrinsicOffset = "$cimageLoad($0, ($1)+($2))$z";
5029
0
        const char* glslIntrinsicMS = "$cimageLoad($0, $1, $2)$z";
5030
0
        const char* glslIntrinsicMSOffset = "$cimageLoad($0, ($1)+($3), $2)$z";
5031
0
SLANG_RAW("#line 4211 \"hlsl.meta.slang\"")
5032
0
SLANG_RAW("\n")
5033
0
SLANG_RAW("\n")
5034
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let isShadow:int, let format:int>\n")
5035
0
SLANG_RAW("extension _Texture<T,Shape,isArray,0,sampleCount,")
5036
0
SLANG_SPLICE(access
5037
0
)
5038
0
SLANG_RAW(",isShadow, 0,format>\n")
5039
0
SLANG_RAW("{\n")
5040
0
SLANG_RAW("    //@hidden:\n")
5041
0
SLANG_RAW("    static const int isMS = 0;\n")
5042
0
SLANG_RAW("    static const int isCombined = 0;\n")
5043
0
SLANG_RAW("\n")
5044
0
SLANG_RAW("    //@public:\n")
5045
0
SLANG_RAW("\n")
5046
5047
0
        if (access != kCoreModule_ResourceAccessWriteOnly)
5048
0
        {
5049
    
5050
0
SLANG_RAW("#line 4225 \"hlsl.meta.slang\"")
5051
0
SLANG_RAW("\n")
5052
0
SLANG_RAW("    [__readNone]\n")
5053
0
SLANG_RAW("    [ForceInline]\n")
5054
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1)]\n")
5055
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location)\n")
5056
0
SLANG_RAW("    {\n")
5057
0
SLANG_RAW("        __target_switch\n")
5058
0
SLANG_RAW("        {\n")
5059
0
SLANG_RAW("            case cpp:\n")
5060
0
SLANG_RAW("            case hlsl:\n")
5061
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
5062
0
SLANG_RAW("            case glsl:\n")
5063
0
SLANG_RAW("                __intrinsic_asm \"")
5064
0
SLANG_SPLICE(glslIntrinsic
5065
0
)
5066
0
SLANG_RAW("\";\n")
5067
0
SLANG_RAW("            case cuda:\n")
5068
0
SLANG_RAW("                if (isArray != 0)\n")
5069
0
SLANG_RAW("                {\n")
5070
0
SLANG_RAW("                    switch(Shape.flavor)\n")
5071
0
SLANG_RAW("                    {\n")
5072
0
SLANG_RAW("                    case ")
5073
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5074
0
)
5075
0
SLANG_RAW(":\n")
5076
0
SLANG_RAW("                        __intrinsic_asm \"surf1DLayeredread$C<$T0>($0, ($1).x * $E, ($1).y, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5077
0
SLANG_RAW("                    case ")
5078
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5079
0
)
5080
0
SLANG_RAW(":\n")
5081
0
SLANG_RAW("                        __intrinsic_asm \"surf2DLayeredread$C<$T0>($0, ($1).x * $E, ($1).y, ($1).z, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5082
0
SLANG_RAW("                    case ")
5083
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5084
0
)
5085
0
SLANG_RAW(":\n")
5086
0
SLANG_RAW("                        __intrinsic_asm \"surf3DLayeredread$C<$T0>($0, ($1).x * $E, ($1).y, ($1).z, ($1).w, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5087
0
SLANG_RAW("                    default:\n")
5088
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
5089
0
SLANG_RAW("                    }\n")
5090
0
SLANG_RAW("                }\n")
5091
0
SLANG_RAW("                else\n")
5092
0
SLANG_RAW("                {\n")
5093
0
SLANG_RAW("                    switch(Shape.flavor)\n")
5094
0
SLANG_RAW("                    {\n")
5095
0
SLANG_RAW("                    case ")
5096
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5097
0
)
5098
0
SLANG_RAW(":\n")
5099
0
SLANG_RAW("                        __intrinsic_asm \"surf1Dread$C<$T0>($0, ($1) * $E, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5100
0
SLANG_RAW("                    case ")
5101
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5102
0
)
5103
0
SLANG_RAW(":\n")
5104
0
SLANG_RAW("                        __intrinsic_asm \"surf2Dread$C<$T0>($0, ($1).x * $E, ($1).y, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5105
0
SLANG_RAW("                    case ")
5106
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5107
0
)
5108
0
SLANG_RAW(":\n")
5109
0
SLANG_RAW("                        __intrinsic_asm \"surf3Dread$C<$T0>($0, ($1).x * $E, ($1).y, ($1).z, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5110
0
SLANG_RAW("                    default:\n")
5111
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
5112
0
SLANG_RAW("                    }\n")
5113
0
SLANG_RAW("                }\n")
5114
0
SLANG_RAW("            case spirv:\n")
5115
0
SLANG_RAW("                return spirv_asm\n")
5116
0
SLANG_RAW("                {\n")
5117
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageRead $this $location;\n")
5118
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
5119
0
SLANG_RAW("                };\n")
5120
0
SLANG_RAW("            case metal:\n")
5121
0
SLANG_RAW("                switch (Shape.flavor)\n")
5122
0
SLANG_RAW("                {\n")
5123
0
SLANG_RAW("                case ")
5124
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5125
0
)
5126
0
SLANG_RAW(":\n")
5127
0
SLANG_RAW("                    // lod is not supported for 1D texture\n")
5128
0
SLANG_RAW("                    if (isArray == 1)\n")
5129
0
SLANG_RAW("                        // Tv read(uint coord, uint array, uint lod = 0) const\n")
5130
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(uint(($1).x), uint(($1).y))$z\";\n")
5131
0
SLANG_RAW("                    else\n")
5132
0
SLANG_RAW("                        // Tv read(uint coord, uint lod = 0) const\n")
5133
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(uint($1))$z\";\n")
5134
0
SLANG_RAW("                    break;\n")
5135
0
SLANG_RAW("                case ")
5136
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5137
0
)
5138
0
SLANG_RAW(":\n")
5139
0
SLANG_RAW("                    if (isShadow == 1)\n")
5140
0
SLANG_RAW("                    {\n")
5141
0
SLANG_RAW("                        if (isArray == 1)\n")
5142
0
SLANG_RAW("                            // T read(uint2 coord, uint array, uint lod = 0) const\n")
5143
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z))$z\";\n")
5144
0
SLANG_RAW("                        else\n")
5145
0
SLANG_RAW("                            // T read(uint2 coord, uint lod = 0) const\n")
5146
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy))$z\";\n")
5147
0
SLANG_RAW("                    }\n")
5148
0
SLANG_RAW("                    else\n")
5149
0
SLANG_RAW("                    {\n")
5150
0
SLANG_RAW("                        if (isArray == 1)\n")
5151
0
SLANG_RAW("                            // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
5152
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z))$z\";\n")
5153
0
SLANG_RAW("                        else\n")
5154
0
SLANG_RAW("                            // Tv read(uint2 coord, uint lod = 0) const\n")
5155
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy))$z\";\n")
5156
0
SLANG_RAW("                    }\n")
5157
0
SLANG_RAW("                    break;\n")
5158
0
SLANG_RAW("                case ")
5159
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5160
0
)
5161
0
SLANG_RAW(":\n")
5162
0
SLANG_RAW("                    if (isShadow == 0 && isArray == 0)\n")
5163
0
SLANG_RAW("                        // Tv read(uint3 coord, uint lod = 0) const\n")
5164
0
SLANG_RAW("                        __intrinsic_asm \"$c$0.read(vec<uint,3>(($1).xyz))$z\";\n")
5165
0
SLANG_RAW("                    break;\n")
5166
0
SLANG_RAW("                case ")
5167
0
SLANG_SPLICE(SLANG_TEXTURE_CUBE
5168
0
)
5169
0
SLANG_RAW(":\n")
5170
0
SLANG_RAW("                    static_assert(isArray == 0, \"Unsupported 'Load' of 'texture cube array' for 'metal' target\");\n")
5171
0
SLANG_RAW("                    if (isShadow == 1)\n")
5172
0
SLANG_RAW("                    {\n")
5173
0
SLANG_RAW("                        if (isArray == 1)\n")
5174
0
SLANG_RAW("                            // T read(uint2 coord, uint face, uint array, uint lod = 0) const\n")
5175
0
SLANG_RAW("                            __intrinsic_asm \"$0.read(vec<uint,2>(($1).xy), uint(($1).z)%6, uint(($1).z)/6, uint(($1).w))\";\n")
5176
0
SLANG_RAW("                        else\n")
5177
0
SLANG_RAW("                            // T read(uint2 coord, uint face, uint lod = 0) const\n")
5178
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
5179
0
SLANG_RAW("                    }\n")
5180
0
SLANG_RAW("                    else\n")
5181
0
SLANG_RAW("                    {\n")
5182
0
SLANG_RAW("                        if (isArray == 1)\n")
5183
0
SLANG_RAW("                            // Tv read(uint2 coord, uint face, uint array, uint lod = 0) const\n")
5184
0
SLANG_RAW("                            __intrinsic_asm \"$0.read(vec<uint,2>(($1).xy), uint(($1).z)%6, uint(($1).z)/6, uint(($1).w))\";\n")
5185
0
SLANG_RAW("                        else\n")
5186
0
SLANG_RAW("                            // Tv read(uint2 coord, uint face, uint lod = 0) const\n")
5187
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), uint(($1).w))$z\";\n")
5188
0
SLANG_RAW("                    }\n")
5189
0
SLANG_RAW("                    break;\n")
5190
0
SLANG_RAW("                }\n")
5191
0
SLANG_RAW("                static_assert(false, \"Unsupported 'Load' of 'texture' for 'metal' target\");\n")
5192
0
SLANG_RAW("                __intrinsic_asm \"<invalid intrinsics>\";\n")
5193
0
SLANG_RAW("            case wgsl:\n")
5194
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, ")
5195
0
SLANG_SPLICE(access
5196
0
)
5197
0
SLANG_RAW(", isShadow, isCombined, format>();\n")
5198
0
SLANG_RAW("\n")
5199
0
SLANG_RAW("                static_assert(Shape.flavor == ")
5200
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5201
0
)
5202
0
SLANG_RAW("\n")
5203
0
SLANG_RAW("                    || Shape.flavor == ")
5204
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5205
0
)
5206
0
SLANG_RAW("\n")
5207
0
SLANG_RAW("                    || Shape.flavor == ")
5208
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5209
0
)
5210
0
SLANG_RAW("\n")
5211
0
SLANG_RAW("                    , \"WGSL does not support textureLoad for Cube texture.\");\n")
5212
0
SLANG_RAW("\n")
5213
0
SLANG_RAW("                if (isArray == 1)\n")
5214
0
SLANG_RAW("                {\n")
5215
0
SLANG_RAW("                    switch (Shape.flavor)\n")
5216
0
SLANG_RAW("                    {\n")
5217
0
SLANG_RAW("                    case ")
5218
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5219
0
)
5220
0
SLANG_RAW(":\n")
5221
0
SLANG_RAW("                        __intrinsic_asm \"textureLoad($0, ($1).xy, i32(($1).z))$z\";\n")
5222
0
SLANG_RAW("                    default:\n")
5223
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic: unimplemented shape>\";\n")
5224
0
SLANG_RAW("                    }\n")
5225
0
SLANG_RAW("                }\n")
5226
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, $1)$z\";\n")
5227
0
SLANG_RAW("        }\n")
5228
0
SLANG_RAW("    }\n")
5229
0
SLANG_RAW("\n")
5230
0
SLANG_RAW("    [__readNone]\n")
5231
0
SLANG_RAW("    [ForceInline]\n")
5232
0
SLANG_RAW("    [require(cpp_glsl_hlsl_spirv, texture_sm_4_1)]\n")
5233
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, vector<int, Shape.dimensions+isArray> offset)\n")
5234
0
SLANG_RAW("    {\n")
5235
0
SLANG_RAW("        __target_switch\n")
5236
0
SLANG_RAW("        {\n")
5237
0
SLANG_RAW("            case cpp:\n")
5238
0
SLANG_RAW("            case hlsl:\n")
5239
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
5240
0
SLANG_RAW("            case glsl:\n")
5241
0
SLANG_RAW("                __intrinsic_asm \"")
5242
0
SLANG_SPLICE(glslIntrinsicOffset
5243
0
)
5244
0
SLANG_RAW("\";\n")
5245
0
SLANG_RAW("            case spirv:\n")
5246
0
SLANG_RAW("                return spirv_asm\n")
5247
0
SLANG_RAW("                {\n")
5248
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageRead $this $location ConstOffset $offset;\n")
5249
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
5250
0
SLANG_RAW("                };\n")
5251
0
SLANG_RAW("        }\n")
5252
0
SLANG_RAW("    }\n")
5253
0
SLANG_RAW("\n")
5254
0
SLANG_RAW("    [__readNone]\n")
5255
0
SLANG_RAW("    [ForceInline]\n")
5256
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, vector<int, Shape.dimensions+isArray> offset, out uint status)\n")
5257
0
SLANG_RAW("    {\n")
5258
0
SLANG_RAW("        __target_switch\n")
5259
0
SLANG_RAW("        {\n")
5260
0
SLANG_RAW("        case hlsl:\n")
5261
0
SLANG_RAW("        case cpp:\n")
5262
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
5263
0
SLANG_RAW("        default:\n")
5264
0
SLANG_RAW("            status = 0;\n")
5265
0
SLANG_RAW("            return Load(location, offset);\n")
5266
0
SLANG_RAW("        }\n")
5267
0
SLANG_RAW("    }\n")
5268
0
SLANG_RAW("\n")
5269
5270
0
        } // if (access != kCoreModule_ResourceAccessWriteOnly)
5271
    
5272
0
SLANG_RAW("#line 4394 \"hlsl.meta.slang\"")
5273
0
SLANG_RAW("\n")
5274
0
SLANG_RAW("    [require(glsl, texture_sm_4_1)]\n")
5275
0
SLANG_RAW("    void __glslImageStore(vector<int, Shape.dimensions+isArray> location, T value)\n")
5276
0
SLANG_RAW("    {\n")
5277
0
SLANG_RAW("        __intrinsic_asm \"imageStore($0, $1, $V2)\";\n")
5278
0
SLANG_RAW("    }\n")
5279
0
SLANG_RAW("\n")
5280
0
SLANG_RAW("    [require(metal, texture_sm_4_1)]\n")
5281
0
SLANG_RAW("    __intrinsic_op(")
5282
0
SLANG_SPLICE(kIROp_ImageStore
5283
0
)
5284
0
SLANG_RAW(")\n")
5285
0
SLANG_RAW("    static void __metalImageStoreArray(This val, vector<uint, Shape.dimensions> location, T value, uint arrayIndex);\n")
5286
0
SLANG_RAW("\n")
5287
0
SLANG_RAW("    [require(metal, texture_sm_4_1)]\n")
5288
0
SLANG_RAW("    __intrinsic_op(")
5289
0
SLANG_SPLICE(kIROp_ImageStore
5290
0
)
5291
0
SLANG_RAW(")\n")
5292
0
SLANG_RAW("    static void __metalImageStore(This val, vector<uint, Shape.dimensions+isArray> location, T value);\n")
5293
0
SLANG_RAW("\n")
5294
0
SLANG_RAW("    [ForceInline]\n")
5295
0
SLANG_RAW("    void Store(vector<uint, Shape.dimensions+isArray> location, T newValue)\n")
5296
0
SLANG_RAW("    {\n")
5297
0
SLANG_RAW("        __target_switch\n")
5298
0
SLANG_RAW("        {\n")
5299
0
SLANG_RAW("            case cpp:\n")
5300
0
SLANG_RAW("            case hlsl:\n")
5301
0
SLANG_RAW("                __intrinsic_asm \".operator[]\";\n")
5302
0
SLANG_RAW("            case glsl:\n")
5303
0
SLANG_RAW("                __glslImageStore(location, newValue);\n")
5304
0
SLANG_RAW("            case cuda:\n")
5305
0
SLANG_RAW("                if (isArray != 0)\n")
5306
0
SLANG_RAW("                {\n")
5307
0
SLANG_RAW("                    switch(Shape.flavor)\n")
5308
0
SLANG_RAW("                    {\n")
5309
0
SLANG_RAW("                    case ")
5310
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5311
0
)
5312
0
SLANG_RAW(":\n")
5313
0
SLANG_RAW("                        __intrinsic_asm \"surf1DLayeredwrite$C<$T0>($2, $0, ($1).x * $E, ($1).y, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5314
0
SLANG_RAW("                    case ")
5315
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5316
0
)
5317
0
SLANG_RAW(":\n")
5318
0
SLANG_RAW("                        __intrinsic_asm \"surf2DLayeredwrite$C<$T0>($2, $0, ($1).x * $E, ($1).y, ($1).z, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5319
0
SLANG_RAW("                    case ")
5320
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5321
0
)
5322
0
SLANG_RAW(":\n")
5323
0
SLANG_RAW("                        __intrinsic_asm \"surf3DLayeredwrite$C<$T0>($2, $0, ($1).x * $E, ($1).y, ($1).z, ($1).w, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5324
0
SLANG_RAW("                    default:\n")
5325
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
5326
0
SLANG_RAW("                    }\n")
5327
0
SLANG_RAW("                }\n")
5328
0
SLANG_RAW("                else\n")
5329
0
SLANG_RAW("                {\n")
5330
0
SLANG_RAW("                    switch(Shape.flavor)\n")
5331
0
SLANG_RAW("                    {\n")
5332
0
SLANG_RAW("                    case ")
5333
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5334
0
)
5335
0
SLANG_RAW(":\n")
5336
0
SLANG_RAW("                        __intrinsic_asm \"surf1Dwrite$C<$T0>($2, $0, ($1) * $E, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5337
0
SLANG_RAW("                    case ")
5338
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5339
0
)
5340
0
SLANG_RAW(":\n")
5341
0
SLANG_RAW("                        __intrinsic_asm \"surf2Dwrite$C<$T0>($2, $0, ($1).x * $E, ($1).y, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5342
0
SLANG_RAW("                    case ")
5343
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5344
0
)
5345
0
SLANG_RAW(":\n")
5346
0
SLANG_RAW("                        __intrinsic_asm \"surf3Dwrite$C<$T0>($2, $0, ($1).x * $E, ($1).y, ($1).z, SLANG_CUDA_BOUNDARY_MODE)\";\n")
5347
0
SLANG_RAW("                    default:\n")
5348
0
SLANG_RAW("                        __intrinsic_asm \"<invalid intrinsic>\";\n")
5349
0
SLANG_RAW("                    }\n")
5350
0
SLANG_RAW("                }\n")
5351
0
SLANG_RAW("            case spirv:\n")
5352
0
SLANG_RAW("                return spirv_asm\n")
5353
0
SLANG_RAW("                {\n")
5354
0
SLANG_RAW("                    OpImageWrite $this $location __convertTexel(newValue);\n")
5355
0
SLANG_RAW("                };\n")
5356
0
SLANG_RAW("            case metal:\n")
5357
0
SLANG_RAW("                if (isArray != 0)\n")
5358
0
SLANG_RAW("                {\n")
5359
0
SLANG_RAW("                    // last arg will be replaced with the split off array index\n")
5360
0
SLANG_RAW("                    __metalImageStoreArray(this, __vectorReshape<Shape.dimensions>(location), newValue, location[Shape.dimensions + isArray - 1]);\n")
5361
0
SLANG_RAW("                }\n")
5362
0
SLANG_RAW("                else\n")
5363
0
SLANG_RAW("                {\n")
5364
0
SLANG_RAW("                    __metalImageStore(this, location, newValue);\n")
5365
0
SLANG_RAW("                }\n")
5366
0
SLANG_RAW("        case wgsl:\n")
5367
0
SLANG_RAW("            __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, ")
5368
0
SLANG_SPLICE(access
5369
0
)
5370
0
SLANG_RAW(", isShadow, isCombined, format>();\n")
5371
0
SLANG_RAW("\n")
5372
0
SLANG_RAW("            static_assert(Shape.flavor == ")
5373
0
SLANG_SPLICE(SLANG_TEXTURE_1D
5374
0
)
5375
0
SLANG_RAW("\n")
5376
0
SLANG_RAW("                || Shape.flavor == ")
5377
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5378
0
)
5379
0
SLANG_RAW("\n")
5380
0
SLANG_RAW("                || Shape.flavor == ")
5381
0
SLANG_SPLICE(SLANG_TEXTURE_3D
5382
0
)
5383
0
SLANG_RAW("\n")
5384
0
SLANG_RAW("                , \"WGSL does not support textureStore for Cube textures.\");\n")
5385
0
SLANG_RAW("\n")
5386
0
SLANG_RAW("            // WGSL requires the value type to be always `vec4`\n")
5387
0
SLANG_RAW("            if (isArray == 1)\n")
5388
0
SLANG_RAW("            {\n")
5389
0
SLANG_RAW("                if (T is int32_t   || T is int16_t  || T is int8_t)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<i32>($V2)\";\n")
5390
0
SLANG_RAW("                if (T is int32_t2  || T is int16_t2  || T is int8_t2)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<i32>($2, 0, 1))\";\n")
5391
0
SLANG_RAW("                if (T is int32_t3  || T is int16_t3  || T is int8_t3)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<i32>($2, 1))\";\n")
5392
0
SLANG_RAW("                if (T is uint32_t  || T is uint16_t || T is uint8_t) __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<u32>($2, 0, 0, 1))\";\n")
5393
0
SLANG_RAW("                if (T is uint32_t2 || T is uint16_t2 || T is uint8_t2) __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<u32>($2, 0, 1))\";\n")
5394
0
SLANG_RAW("                if (T is uint32_t3 || T is uint16_t3 || T is uint8_t3) __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<u32>($2, 1))\";\n")
5395
0
SLANG_RAW("                if (T is half)   __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f16>($2, 0, 0, 1))\";\n")
5396
0
SLANG_RAW("                if (T is half2)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f16>($2, 0, 1))\";\n")
5397
0
SLANG_RAW("                if (T is half3)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f16>($2, 1))\";\n")
5398
0
SLANG_RAW("                if (T is float)  __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f32>($2, 0, 0, 1))\";\n")
5399
0
SLANG_RAW("                if (T is float2) __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f32>($2, 0, 1))\";\n")
5400
0
SLANG_RAW("                if (T is float3) __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), vec4<f32>($2, 1))\";\n")
5401
0
SLANG_RAW("                __intrinsic_asm \"textureStore($0, ($1).xy, i32(($1).z), $2)\";\n")
5402
0
SLANG_RAW("            }\n")
5403
0
SLANG_RAW("            if (T is int32_t   || T is int16_t  || T is int8_t)  __intrinsic_asm \"textureStore($0, $1, vec4<i32>($2, 0, 0, 1))\";\n")
5404
0
SLANG_RAW("            if (T is int32_t2  || T is int16_t2 || T is int8_t2)  __intrinsic_asm \"textureStore($0, $1, vec4<i32>($2, 0, 1))\";\n")
5405
0
SLANG_RAW("            if (T is int32_t3  || T is int16_t3 || T is int8_t3)  __intrinsic_asm \"textureStore($0, $1, vec4<i32>($2, 1))\";\n")
5406
0
SLANG_RAW("            if (T is uint32_t  || T is uint16_t || T is uint8_t) __intrinsic_asm \"textureStore($0, $1, vec4<u32>($2, 0, 0, 1))\";\n")
5407
0
SLANG_RAW("            if (T is uint32_t2 || T is uint16_t2 || T is uint8_t2) __intrinsic_asm \"textureStore($0, $1, vec4<u32>($2, 0, 1))\";\n")
5408
0
SLANG_RAW("            if (T is uint32_t3 || T is uint16_t3 || T is uint8_t3) __intrinsic_asm \"textureStore($0, $1, vec4<u32>($2, 1))\";\n")
5409
0
SLANG_RAW("            if (T is half)   __intrinsic_asm \"textureStore($0, $1, vec4<f16>($2, 0, 0, 1))\";\n")
5410
0
SLANG_RAW("            if (T is half2)  __intrinsic_asm \"textureStore($0, $1, vec4<f16>($2, 0, 1))\";\n")
5411
0
SLANG_RAW("            if (T is half3)  __intrinsic_asm \"textureStore($0, $1, vec4<f16>($2, 1))\";\n")
5412
0
SLANG_RAW("            if (T is float)  __intrinsic_asm \"textureStore($0, $1, vec4<f32>($2, 0, 0, 1))\";\n")
5413
0
SLANG_RAW("            if (T is float2) __intrinsic_asm \"textureStore($0, $1, vec4<f32>($2, 0, 1))\";\n")
5414
0
SLANG_RAW("            if (T is float3) __intrinsic_asm \"textureStore($0, $1, vec4<f32>($2, 1))\";\n")
5415
0
SLANG_RAW("            __intrinsic_asm \"textureStore($0, $1, $2)\";\n")
5416
0
SLANG_RAW("        }\n")
5417
0
SLANG_RAW("    }\n")
5418
0
SLANG_RAW("\n")
5419
5420
0
        if (access != kCoreModule_ResourceAccessWriteOnly)
5421
0
        {
5422
    
5423
0
SLANG_RAW("#line 4507 \"hlsl.meta.slang\"")
5424
0
SLANG_RAW("\n")
5425
0
SLANG_RAW("    __subscript(vector<uint, Shape.dimensions+isArray> location) -> T\n")
5426
0
SLANG_RAW("    {\n")
5427
0
SLANG_RAW("        [__readNone]\n")
5428
0
SLANG_RAW("        [ForceInline]\n")
5429
0
SLANG_RAW("        [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1)]\n")
5430
0
SLANG_RAW("        get\n")
5431
0
SLANG_RAW("        {\n")
5432
0
SLANG_RAW("            __target_switch\n")
5433
0
SLANG_RAW("            {\n")
5434
0
SLANG_RAW("                case cpp:\n")
5435
0
SLANG_RAW("                case hlsl:\n")
5436
0
SLANG_RAW("                    __intrinsic_asm \".operator[]\";\n")
5437
0
SLANG_RAW("                case glsl:\n")
5438
0
SLANG_RAW("                case spirv:\n")
5439
0
SLANG_RAW("                case cuda:\n")
5440
0
SLANG_RAW("                case metal:\n")
5441
0
SLANG_RAW("                case wgsl:\n")
5442
0
SLANG_RAW("                    return Load(location);\n")
5443
0
SLANG_RAW("            }\n")
5444
0
SLANG_RAW("        }\n")
5445
0
SLANG_RAW("\n")
5446
0
SLANG_RAW("        [nonmutating]\n")
5447
0
SLANG_RAW("        [ForceInline]\n")
5448
0
SLANG_RAW("        [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1)]\n")
5449
0
SLANG_RAW("        set(T newValue)\n")
5450
0
SLANG_RAW("        {\n")
5451
0
SLANG_RAW("            Store(location, newValue);\n")
5452
0
SLANG_RAW("        }\n")
5453
0
SLANG_RAW("\n")
5454
0
SLANG_RAW("        // If a 'Texture[location]' is referred to by a '__ref', call 'kIROp_ImageSubscript(location)'.\n")
5455
0
SLANG_RAW("        // This allows call's to stay aware that the input is from a 'Texture'.\n")
5456
0
SLANG_RAW("        __intrinsic_op(")
5457
0
SLANG_SPLICE(kIROp_ImageSubscript
5458
0
)
5459
0
SLANG_RAW(")\n")
5460
0
SLANG_RAW("        [nonmutating]\n")
5461
0
SLANG_RAW("        ref;\n")
5462
0
SLANG_RAW("    }\n")
5463
5464
0
        } // if (access != kCoreModule_ResourceAccessWriteOnly)
5465
    
5466
0
SLANG_RAW("#line 4545 \"hlsl.meta.slang\"")
5467
0
SLANG_RAW("\n")
5468
0
SLANG_RAW("\n")
5469
0
SLANG_RAW("}\n")
5470
0
SLANG_RAW("\n")
5471
5472
0
if (access == kCoreModule_ResourceAccessReadWrite) {
5473
0
SLANG_RAW("#line 4551 \"hlsl.meta.slang\"")
5474
0
SLANG_RAW("\n")
5475
0
SLANG_RAW("\n")
5476
0
SLANG_RAW("// RW MS textures.\n")
5477
0
SLANG_RAW("\n")
5478
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let sampleCount:int, let isShadow:int, let format:int>\n")
5479
0
SLANG_RAW("extension _Texture<T,Shape,isArray,1,sampleCount,")
5480
0
SLANG_SPLICE(access
5481
0
)
5482
0
SLANG_RAW(",isShadow, 0,format>\n")
5483
0
SLANG_RAW("{\n")
5484
0
SLANG_RAW("    //@hidden:\n")
5485
0
SLANG_RAW("    static const int isMS = 1;\n")
5486
0
SLANG_RAW("    static const int isCombined = 0;\n")
5487
0
SLANG_RAW("\n")
5488
0
SLANG_RAW("    //@public:\n")
5489
0
SLANG_RAW("\n")
5490
0
SLANG_RAW("    [__readNone]\n")
5491
0
SLANG_RAW("    [ForceInline]\n")
5492
0
SLANG_RAW("    [require(cpp_glsl_hlsl_metal_spirv_wgsl, texture_sm_4_1_compute_fragment)]\n")
5493
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex)\n")
5494
0
SLANG_RAW("    {\n")
5495
0
SLANG_RAW("        __target_switch\n")
5496
0
SLANG_RAW("        {\n")
5497
0
SLANG_RAW("            case cpp:\n")
5498
0
SLANG_RAW("            case hlsl:\n")
5499
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
5500
0
SLANG_RAW("            case metal:\n")
5501
0
SLANG_RAW("                switch (Shape.flavor)\n")
5502
0
SLANG_RAW("                {\n")
5503
0
SLANG_RAW("                case ")
5504
0
SLANG_SPLICE(SLANG_TEXTURE_2D
5505
0
)
5506
0
SLANG_RAW(":\n")
5507
0
SLANG_RAW("                    if (isShadow == 1)\n")
5508
0
SLANG_RAW("                    {\n")
5509
0
SLANG_RAW("                        if (isArray == 1)\n")
5510
0
SLANG_RAW("                            // The document seems to have a typo. `lod` must mean `sample`.\n")
5511
0
SLANG_RAW("                            // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
5512
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), $2)$z\";\n")
5513
0
SLANG_RAW("                        else\n")
5514
0
SLANG_RAW("                            // T read(uint2 coord, uint sample) const\n")
5515
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), $2)$z\";\n")
5516
0
SLANG_RAW("                    }\n")
5517
0
SLANG_RAW("                    else\n")
5518
0
SLANG_RAW("                    {\n")
5519
0
SLANG_RAW("                        if (isArray == 1)\n")
5520
0
SLANG_RAW("                            // The document seems to have a typo. `lod` must mean `sample`.\n")
5521
0
SLANG_RAW("                            // Tv read(uint2 coord, uint array, uint lod = 0) const\n")
5522
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), uint(($1).z), $2)$z\";\n")
5523
0
SLANG_RAW("                        else\n")
5524
0
SLANG_RAW("                            // Tv read(uint2 coord, uint sample) const\n")
5525
0
SLANG_RAW("                            __intrinsic_asm \"$c$0.read(vec<uint,2>(($1).xy), $2)$z\";\n")
5526
0
SLANG_RAW("                    }\n")
5527
0
SLANG_RAW("                    break;\n")
5528
0
SLANG_RAW("                }\n")
5529
0
SLANG_RAW("                // TODO: This needs to be handled by the capability system\n")
5530
0
SLANG_RAW("                __intrinsic_asm \"<Not supported>\";\n")
5531
0
SLANG_RAW("            case glsl:\n")
5532
0
SLANG_RAW("                __intrinsic_asm \"")
5533
0
SLANG_SPLICE(glslIntrinsicMS
5534
0
)
5535
0
SLANG_RAW("\";\n")
5536
0
SLANG_RAW("            case spirv:\n")
5537
0
SLANG_RAW("                return spirv_asm\n")
5538
0
SLANG_RAW("                {\n")
5539
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageRead $this $location Sample $sampleIndex;\n")
5540
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
5541
0
SLANG_RAW("                };\n")
5542
0
SLANG_RAW("            case wgsl:\n")
5543
0
SLANG_RAW("                __wgsl_check_texture_type<T, Shape, isArray, isMS, sampleCount, ")
5544
0
SLANG_SPLICE(access
5545
0
)
5546
0
SLANG_RAW(", isShadow, isCombined, format>();\n")
5547
0
SLANG_RAW("\n")
5548
0
SLANG_RAW("                __intrinsic_asm \"textureLoad($0, $1, $2)$z\";\n")
5549
0
SLANG_RAW("        }\n")
5550
0
SLANG_RAW("    }\n")
5551
0
SLANG_RAW("\n")
5552
0
SLANG_RAW("    [__readNone]\n")
5553
0
SLANG_RAW("    [ForceInline]\n")
5554
0
SLANG_RAW("    [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_compute_fragment)]\n")
5555
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex, vector<int, Shape.dimensions+isArray> offset)\n")
5556
0
SLANG_RAW("    {\n")
5557
0
SLANG_RAW("        __target_switch\n")
5558
0
SLANG_RAW("        {\n")
5559
0
SLANG_RAW("            case cpp:\n")
5560
0
SLANG_RAW("            case hlsl:\n")
5561
0
SLANG_RAW("                __intrinsic_asm \".Load\";\n")
5562
0
SLANG_RAW("            case glsl:\n")
5563
0
SLANG_RAW("                __intrinsic_asm \"")
5564
0
SLANG_SPLICE(glslIntrinsicMSOffset
5565
0
)
5566
0
SLANG_RAW("\";\n")
5567
0
SLANG_RAW("            case spirv:\n")
5568
0
SLANG_RAW("                return spirv_asm\n")
5569
0
SLANG_RAW("                {\n")
5570
0
SLANG_RAW("                    %sampled:__sampledType(T) = OpImageRead $this $location ConstOffset|Sample $offset $sampleIndex;\n")
5571
0
SLANG_RAW("                    __truncate $$T result __sampledType(T) %sampled;\n")
5572
0
SLANG_RAW("                };\n")
5573
0
SLANG_RAW("        }\n")
5574
0
SLANG_RAW("    }\n")
5575
0
SLANG_RAW("\n")
5576
0
SLANG_RAW("    [__readNone]\n")
5577
0
SLANG_RAW("    [ForceInline]\n")
5578
0
SLANG_RAW("    T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex, vector<int, Shape.dimensions+isArray> offset, out uint status)\n")
5579
0
SLANG_RAW("    {\n")
5580
0
SLANG_RAW("        __target_switch\n")
5581
0
SLANG_RAW("        {\n")
5582
0
SLANG_RAW("        case hlsl:\n")
5583
0
SLANG_RAW("        case cpp:\n")
5584
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
5585
0
SLANG_RAW("        default:\n")
5586
0
SLANG_RAW("            status = 0;\n")
5587
0
SLANG_RAW("            return Load(location, sampleIndex, offset);\n")
5588
0
SLANG_RAW("        }\n")
5589
0
SLANG_RAW("    }\n")
5590
0
SLANG_RAW("\n")
5591
0
SLANG_RAW("    [require(glsl, texture_sm_4_1_compute_fragment)]\n")
5592
0
SLANG_RAW("    void __glslImageStore(vector<int, Shape.dimensions+isArray> location, int sampleIndex, T value)\n")
5593
0
SLANG_RAW("    {\n")
5594
0
SLANG_RAW("        __intrinsic_asm \"imageStore($0, $1, $2, $V3)\";\n")
5595
0
SLANG_RAW("    }\n")
5596
0
SLANG_RAW("\n")
5597
0
SLANG_RAW("    __subscript(vector<uint, Shape.dimensions+isArray> location, int sampleIndex) -> T\n")
5598
0
SLANG_RAW("    {\n")
5599
0
SLANG_RAW("        [__readNone]\n")
5600
0
SLANG_RAW("        [ForceInline]\n")
5601
0
SLANG_RAW("        [require(cpp_glsl_hlsl_spirv_wgsl, texture_sm_4_1_compute_fragment)]\n")
5602
0
SLANG_RAW("        get\n")
5603
0
SLANG_RAW("        {\n")
5604
0
SLANG_RAW("            __target_switch\n")
5605
0
SLANG_RAW("            {\n")
5606
0
SLANG_RAW("                case cpp:\n")
5607
0
SLANG_RAW("                case hlsl:\n")
5608
0
SLANG_RAW("                    __intrinsic_asm \"$0.sample[$2][$1]\";\n")
5609
0
SLANG_RAW("                case glsl:\n")
5610
0
SLANG_RAW("                case spirv:\n")
5611
0
SLANG_RAW("                case wgsl:\n")
5612
0
SLANG_RAW("                    return Load(location, sampleIndex);\n")
5613
0
SLANG_RAW("            }\n")
5614
0
SLANG_RAW("        }\n")
5615
0
SLANG_RAW("\n")
5616
0
SLANG_RAW("        [nonmutating]\n")
5617
0
SLANG_RAW("        [ForceInline]\n")
5618
0
SLANG_RAW("        [require(cpp_glsl_hlsl_spirv, texture_sm_4_1_compute_fragment)]\n")
5619
0
SLANG_RAW("        set(T newValue)\n")
5620
0
SLANG_RAW("        {\n")
5621
0
SLANG_RAW("            __target_switch\n")
5622
0
SLANG_RAW("            {\n")
5623
0
SLANG_RAW("                case cpp:\n")
5624
0
SLANG_RAW("                case hlsl:\n")
5625
0
SLANG_RAW("                    __intrinsic_asm \"$0.sample[$2][$1]\";\n")
5626
0
SLANG_RAW("                case glsl:\n")
5627
0
SLANG_RAW("                    __glslImageStore(location, sampleIndex, newValue);\n")
5628
0
SLANG_RAW("                case spirv:\n")
5629
0
SLANG_RAW("                    return spirv_asm\n")
5630
0
SLANG_RAW("                    {\n")
5631
0
SLANG_RAW("                        OpImageWrite $this $location __convertTexel(newValue) Sample $sampleIndex;\n")
5632
0
SLANG_RAW("                    };\n")
5633
0
SLANG_RAW("            }\n")
5634
0
SLANG_RAW("        }\n")
5635
0
SLANG_RAW("\n")
5636
0
SLANG_RAW("        // If a 'Texture[location, sampleIndex]' is referred to by a '__ref', call 'kIROp_ImageSubscript(location, sampleIndex)'.\n")
5637
0
SLANG_RAW("        // This allows call's to stay aware that the input is from a 'Texture'.\n")
5638
0
SLANG_RAW("        __intrinsic_op(")
5639
0
SLANG_SPLICE(kIROp_ImageSubscript
5640
0
)
5641
0
SLANG_RAW(")\n")
5642
0
SLANG_RAW("        [nonmutating]\n")
5643
0
SLANG_RAW("        ref;\n")
5644
0
SLANG_RAW("    }\n")
5645
0
SLANG_RAW("}\n")
5646
0
SLANG_RAW("\n")
5647
5648
0
} // if (access == kCoreModule_ResourceAccessReadWrite) // for RW MS textures.
5649
0
} // for (access).
5650
0
SLANG_RAW("#line 4709 \"hlsl.meta.slang\"")
5651
0
SLANG_RAW("\n")
5652
0
SLANG_RAW("\n")
5653
0
SLANG_RAW("// Definitions to support the legacy texture .mips[][] operator.\n")
5654
0
SLANG_RAW("struct __TextureMip<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5655
0
SLANG_RAW("{\n")
5656
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex;\n")
5657
0
SLANG_RAW("    int mip;\n")
5658
0
SLANG_RAW("    __subscript(vector<int, isArray + Shape.dimensions> pos)->T\n")
5659
0
SLANG_RAW("    {\n")
5660
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5661
0
SLANG_RAW("        get { return tex.Load(__makeVector(pos, mip)); }\n")
5662
0
SLANG_RAW("    }\n")
5663
0
SLANG_RAW("}\n")
5664
0
SLANG_RAW("\n")
5665
0
SLANG_RAW("struct __TextureMips<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5666
0
SLANG_RAW("{\n")
5667
0
SLANG_RAW("    _Texture<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex;\n")
5668
0
SLANG_RAW("    __subscript(int mip)->__TextureMip<T, Shape, isArray, isCombined, format>\n")
5669
0
SLANG_RAW("    {\n")
5670
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5671
0
SLANG_RAW("        get { return { tex, mip }; }\n")
5672
0
SLANG_RAW("    }\n")
5673
0
SLANG_RAW("}\n")
5674
0
SLANG_RAW("\n")
5675
0
SLANG_RAW("//@hidden:\n")
5676
0
SLANG_RAW("__generic<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5677
0
SLANG_RAW("extension _Texture<T, Shape, isArray, 0 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format>\n")
5678
0
SLANG_RAW("{\n")
5679
0
SLANG_RAW("    property __TextureMips<T, Shape, isArray, isCombined, format> mips\n")
5680
0
SLANG_RAW("    {\n")
5681
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5682
0
SLANG_RAW("        get { return { this }; }\n")
5683
0
SLANG_RAW("    }\n")
5684
0
SLANG_RAW("}\n")
5685
0
SLANG_RAW("\n")
5686
0
SLANG_RAW("// Definitions to support the .sample[][] operator.\n")
5687
0
SLANG_RAW("struct __TextureSample<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5688
0
SLANG_RAW("{\n")
5689
0
SLANG_RAW("    _Texture<T, Shape, isArray, 1 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex;\n")
5690
0
SLANG_RAW("    int sample;\n")
5691
0
SLANG_RAW("    __subscript(vector<int, isArray + Shape.dimensions> pos)->T\n")
5692
0
SLANG_RAW("    {\n")
5693
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5694
0
SLANG_RAW("        get { return tex[pos, sample]; }\n")
5695
0
SLANG_RAW("    }\n")
5696
0
SLANG_RAW("}\n")
5697
0
SLANG_RAW("\n")
5698
0
SLANG_RAW("struct __TextureSampleMS<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5699
0
SLANG_RAW("{\n")
5700
0
SLANG_RAW("    _Texture<T, Shape, isArray, 1 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format> tex;\n")
5701
0
SLANG_RAW("    __subscript(int sample)->__TextureSample<T, Shape, isArray, isCombined, format>\n")
5702
0
SLANG_RAW("    {\n")
5703
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5704
0
SLANG_RAW("        get { return { tex, sample }; }\n")
5705
0
SLANG_RAW("    }\n")
5706
0
SLANG_RAW("}\n")
5707
0
SLANG_RAW("\n")
5708
0
SLANG_RAW("__generic<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isCombined : int, let format : int>\n")
5709
0
SLANG_RAW("extension _Texture<T, Shape, isArray, 1 /*isMS*/, 0 /*sampleCount*/, 0 /*access*/, 0 /*isShadow*/, isCombined, format>\n")
5710
0
SLANG_RAW("{\n")
5711
0
SLANG_RAW("    property __TextureSampleMS<T, Shape, isArray, isCombined, format> sample\n")
5712
0
SLANG_RAW("    {\n")
5713
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
5714
0
SLANG_RAW("        get { return { this }; }\n")
5715
0
SLANG_RAW("    }\n")
5716
0
SLANG_RAW("}\n")
5717
0
SLANG_RAW("\n")
5718
0
SLANG_RAW("//@public:\n")
5719
0
SLANG_RAW("\n")
5720
0
SLANG_RAW("// Texture type aliases.\n")
5721
0
SLANG_RAW("// T, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int\n")
5722
5723
0
    const char* shapeTypeNames[] = {"1D", "2D", "3D", "Cube"};
5724
0
    const char* accessPrefix[] = {"", "RW", "W", "RasterizerOrdered", "Feedback"};
5725
0
    const char* accessDocumentation[] = {"read-only", "read-write", "write-only", "rasterizer-ordered", "feedback"};
5726
0
    const char* arrayPostFix[] = {"", "Array"};
5727
0
    const char* msPostFix[] = {"", "MS"};
5728
0
    for (int shape = 0; shape < 4; shape++)
5729
0
    for (int isArray = 0; isArray<=1; isArray++)
5730
0
    for (int isMS = 0; isMS<=1; isMS++)
5731
0
    for (int isCombined = 0; isCombined<=1; isCombined++)
5732
0
    for (int access = kCoreModule_ResourceAccessReadOnly; access <= kCoreModule_ResourceAccessFeedback; access++) {
5733
0
        if (access != kCoreModule_ResourceAccessReadOnly)
5734
0
        {
5735
            // No RW Cube.
5736
0
            if (shape == kCoreModule_ShapeIndexCube) continue;
5737
0
        }
5738
0
        if (access == kCoreModule_ResourceAccessFeedback)
5739
0
        {
5740
            // Feedback only defined for Texture2D and Texture2DArray.
5741
0
            if (shape != 1) continue;
5742
0
            if (isMS) continue;
5743
0
            if (isCombined) continue;
5744
0
        }
5745
0
        if (isMS)
5746
0
        {
5747
            // Only Texture2DMS.
5748
0
            if (shape != kCoreModule_ShapeIndex2D)
5749
0
                continue;
5750
            // Only Texture2DMS or RWTexture2DMS.
5751
0
            if (access >= kCoreModule_ShapeIndex3D)
5752
0
                continue;
5753
0
        }
5754
        // No 3D Array.
5755
0
        if (shape == kCoreModule_ShapeIndex3D && isArray == 1)
5756
0
            continue;
5757
0
        const char* textureTypeName = isCombined ? "Sampler" : "Texture";
5758
0
SLANG_RAW("#line 4816 \"hlsl.meta.slang\"")
5759
0
SLANG_RAW("\n")
5760
0
SLANG_RAW("/// Represents a handle to a ")
5761
0
SLANG_SPLICE(accessDocumentation[access]
5762
0
)
5763
0
SLANG_SPLICE(isMS?", multisampled": ""
5764
0
)
5765
0
SLANG_RAW(" ")
5766
0
SLANG_SPLICE(shapeTypeNames[shape]
5767
0
)
5768
0
SLANG_RAW(" ")
5769
0
SLANG_SPLICE(isCombined?"combined texture-sampler": "texture"
5770
0
)
5771
0
SLANG_SPLICE(isArray?" array":""
5772
0
)
5773
0
SLANG_RAW(".\n")
5774
0
SLANG_RAW("/// @param T The texel type of the texture.\n")
5775
0
SLANG_RAW("/// @param sampleCount The number of samples in the texture, when the texture is multisampled.\n")
5776
0
SLANG_RAW("/// @param format The storage format of the texture.\n")
5777
0
SLANG_RAW("/// @see Please refer to `_Texture` for more information about texture types.\n")
5778
0
SLANG_RAW("/// @category texture_types\n")
5779
0
SLANG_RAW("typealias ")
5780
0
SLANG_SPLICE(accessPrefix[access]
5781
0
)
5782
0
SLANG_SPLICE(textureTypeName
5783
0
)
5784
0
SLANG_SPLICE(shapeTypeNames[shape]
5785
0
)
5786
0
SLANG_SPLICE(msPostFix[isMS]
5787
0
)
5788
0
SLANG_SPLICE(arrayPostFix[isArray]
5789
0
)
5790
0
SLANG_RAW("<T:ITexelElement=float4, let sampleCount:int=0, let format:int=0> = _Texture<T, __Shape")
5791
0
SLANG_SPLICE(shapeTypeNames[shape]
5792
0
)
5793
0
SLANG_RAW(", ")
5794
0
SLANG_SPLICE(isArray
5795
0
)
5796
0
SLANG_RAW(", ")
5797
0
SLANG_SPLICE(isMS
5798
0
)
5799
0
SLANG_RAW(", sampleCount, ")
5800
0
SLANG_SPLICE(access
5801
0
)
5802
0
SLANG_RAW(", 0, ")
5803
0
SLANG_SPLICE(isCombined
5804
0
)
5805
0
SLANG_RAW(", format>;\n")
5806
5807
0
}
5808
0
SLANG_RAW("#line 4826 \"hlsl.meta.slang\"")
5809
0
SLANG_RAW("\n")
5810
0
SLANG_RAW("\n")
5811
0
SLANG_RAW("// Declare DepthTexture* and Sampler*Shadow type aliases.\n")
5812
5813
0
    for (int shape = 0; shape < 4; shape++)
5814
0
    for (int isArray : { 0, 1 })
5815
0
    for (int isMS : { 0, 1 })
5816
0
    {
5817
0
        if (isMS)
5818
0
        {
5819
            // Only DepthTexture2DMS and Sampler2DMSShadow.
5820
0
            if (shape != kCoreModule_ShapeIndex2D)
5821
0
                continue;
5822
0
        }
5823
5824
        // No 3D Array.
5825
0
        if (shape == kCoreModule_ShapeIndex3D && isArray == 1)
5826
0
            continue;
5827
0
SLANG_RAW("#line 4844 \"hlsl.meta.slang\"")
5828
0
SLANG_RAW("\n")
5829
0
SLANG_RAW("/// Represents a handle to a")
5830
0
SLANG_SPLICE(isMS?" multisampled": ""
5831
0
)
5832
0
SLANG_RAW(" ")
5833
0
SLANG_SPLICE(shapeTypeNames[shape]
5834
0
)
5835
0
SLANG_RAW(" depth texture")
5836
0
SLANG_SPLICE(isArray?" array":""
5837
0
)
5838
0
SLANG_RAW(".\n")
5839
0
SLANG_RAW("/// @param format The storage format of the texture.\n")
5840
0
SLANG_RAW("/// @see Please refer to `_Texture` for more information about texture types.\n")
5841
0
SLANG_RAW("/// @category texture_types\n")
5842
0
SLANG_RAW("typealias DepthTexture")
5843
0
SLANG_SPLICE(shapeTypeNames[shape]
5844
0
)
5845
0
SLANG_SPLICE(msPostFix[isMS]
5846
0
)
5847
0
SLANG_SPLICE(arrayPostFix[isArray]
5848
0
)
5849
0
SLANG_RAW("<int format=0> = _Texture<float, __Shape")
5850
0
SLANG_SPLICE(shapeTypeNames[shape]
5851
0
)
5852
0
SLANG_RAW(", ")
5853
0
SLANG_SPLICE(isArray
5854
0
)
5855
0
SLANG_RAW(", ")
5856
0
SLANG_SPLICE(isMS
5857
0
)
5858
0
SLANG_RAW(", 0, 0, 1, 0, format>;\n")
5859
0
SLANG_RAW("\n")
5860
0
SLANG_RAW("/// Represents a handle to a")
5861
0
SLANG_SPLICE(isMS?" multisampled": ""
5862
0
)
5863
0
SLANG_RAW(" ")
5864
0
SLANG_SPLICE(shapeTypeNames[shape]
5865
0
)
5866
0
SLANG_RAW(" combined texture-sampler")
5867
0
SLANG_SPLICE(isArray?" array":""
5868
0
)
5869
0
SLANG_RAW(" for shadow comparison.\n")
5870
0
SLANG_RAW("/// @param format The storage format of the texture.\n")
5871
0
SLANG_RAW("/// @see Please refer to `_Texture` for more information about texture types.\n")
5872
0
SLANG_RAW("/// @category texture_types\n")
5873
0
SLANG_RAW("typealias Sampler")
5874
0
SLANG_SPLICE(shapeTypeNames[shape]
5875
0
)
5876
0
SLANG_SPLICE(msPostFix[isMS]
5877
0
)
5878
0
SLANG_SPLICE(arrayPostFix[isArray]
5879
0
)
5880
0
SLANG_RAW("Shadow<int format=0> = _Texture<float, __Shape")
5881
0
SLANG_SPLICE(shapeTypeNames[shape]
5882
0
)
5883
0
SLANG_RAW(", ")
5884
0
SLANG_SPLICE(isArray
5885
0
)
5886
0
SLANG_RAW(", ")
5887
0
SLANG_SPLICE(isMS
5888
0
)
5889
0
SLANG_RAW(", 0, 0, 1, 1, format>;\n")
5890
0
SLANG_RAW("\n")
5891
5892
0
    }
5893
0
SLANG_RAW("#line 4859 \"hlsl.meta.slang\"")
5894
0
SLANG_RAW("\n")
5895
0
SLANG_RAW("\n")
5896
0
SLANG_RAW("// Atomic intrinsic insts.\n")
5897
0
SLANG_RAW("\n")
5898
0
SLANG_RAW("__intrinsic_op(")
5899
0
SLANG_SPLICE(kIROp_AtomicExchange
5900
0
)
5901
0
SLANG_RAW(")\n")
5902
0
SLANG_RAW("T __atomic_exchange<T>(__ref T val, T newValue, MemoryOrder order = MemoryOrder.Relaxed);\n")
5903
0
SLANG_RAW("__intrinsic_op(")
5904
0
SLANG_SPLICE(kIROp_AtomicCompareExchange
5905
0
)
5906
0
SLANG_RAW(")\n")
5907
0
SLANG_RAW("T __atomic_compare_exchange<T>(\n")
5908
0
SLANG_RAW("    __ref T val,\n")
5909
0
SLANG_RAW("    T compareValue,\n")
5910
0
SLANG_RAW("    T newValue,\n")
5911
0
SLANG_RAW("    MemoryOrder successOrder = MemoryOrder.Relaxed,\n")
5912
0
SLANG_RAW("    MemoryOrder failOrder = MemoryOrder.Relaxed);\n")
5913
0
SLANG_RAW("__intrinsic_op(")
5914
0
SLANG_SPLICE(kIROp_AtomicAdd
5915
0
)
5916
0
SLANG_RAW(")\n")
5917
0
SLANG_RAW("T __atomic_add<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5918
0
SLANG_RAW("__intrinsic_op(")
5919
0
SLANG_SPLICE(kIROp_AtomicSub
5920
0
)
5921
0
SLANG_RAW(")\n")
5922
0
SLANG_RAW("T __atomic_sub<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5923
0
SLANG_RAW("__intrinsic_op(")
5924
0
SLANG_SPLICE(kIROp_AtomicMax
5925
0
)
5926
0
SLANG_RAW(")\n")
5927
0
SLANG_RAW("T __atomic_max<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5928
0
SLANG_RAW("__intrinsic_op(")
5929
0
SLANG_SPLICE(kIROp_AtomicMin
5930
0
)
5931
0
SLANG_RAW(")\n")
5932
0
SLANG_RAW("T __atomic_min<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5933
0
SLANG_RAW("__intrinsic_op(")
5934
0
SLANG_SPLICE(kIROp_AtomicAnd
5935
0
)
5936
0
SLANG_RAW(")\n")
5937
0
SLANG_RAW("T __atomic_and<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5938
0
SLANG_RAW("__intrinsic_op(")
5939
0
SLANG_SPLICE(kIROp_AtomicOr
5940
0
)
5941
0
SLANG_RAW(")\n")
5942
0
SLANG_RAW("T __atomic_or<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5943
0
SLANG_RAW("__intrinsic_op(")
5944
0
SLANG_SPLICE(kIROp_AtomicXor
5945
0
)
5946
0
SLANG_RAW(")\n")
5947
0
SLANG_RAW("T __atomic_xor<T>(__ref T val, T value, MemoryOrder order = MemoryOrder.Relaxed);\n")
5948
0
SLANG_RAW("__intrinsic_op(")
5949
0
SLANG_SPLICE(kIROp_AtomicInc
5950
0
)
5951
0
SLANG_RAW(")\n")
5952
0
SLANG_RAW("T __atomic_increment<T>(__ref T val, MemoryOrder order = MemoryOrder.Relaxed);\n")
5953
0
SLANG_RAW("__intrinsic_op(")
5954
0
SLANG_SPLICE(kIROp_AtomicDec
5955
0
)
5956
0
SLANG_RAW(")\n")
5957
0
SLANG_RAW("T __atomic_decrement<T>(__ref T val, MemoryOrder order = MemoryOrder.Relaxed);\n")
5958
0
SLANG_RAW("\n")
5959
0
SLANG_RAW("// Conversion between uint64_t and uint2\n")
5960
0
SLANG_RAW("\n")
5961
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)]\n")
5962
0
SLANG_RAW("uint2 __asuint2(uint64_t i)\n")
5963
0
SLANG_RAW("{\n")
5964
0
SLANG_RAW("    return uint2(uint(i), uint(uint64_t(i) >> 32));\n")
5965
0
SLANG_RAW("}\n")
5966
0
SLANG_RAW("\n")
5967
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)]\n")
5968
0
SLANG_RAW("uint64_t __asuint64(uint2 i)\n")
5969
0
SLANG_RAW("{\n")
5970
0
SLANG_RAW("    return (uint64_t(i.y) << 32) | i.x;\n")
5971
0
SLANG_RAW("}\n")
5972
0
SLANG_RAW("\n")
5973
0
SLANG_RAW("//\n")
5974
0
SLANG_RAW("\n")
5975
0
SLANG_RAW("__intrinsic_op(")
5976
0
SLANG_SPLICE(kIROp_ByteAddressBufferLoad
5977
0
)
5978
0
SLANG_RAW(")\n")
5979
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer)]\n")
5980
0
SLANG_RAW("T __byteAddressBufferLoad<T>(ByteAddressBuffer buffer, uint offset, uint alignment);\n")
5981
0
SLANG_RAW("\n")
5982
0
SLANG_RAW("__intrinsic_op(")
5983
0
SLANG_SPLICE(kIROp_ByteAddressBufferLoad
5984
0
)
5985
0
SLANG_RAW(")\n")
5986
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer_rw)]\n")
5987
0
SLANG_RAW("T __byteAddressBufferLoad<T>(RWByteAddressBuffer buffer, uint offset, uint alignment);\n")
5988
0
SLANG_RAW("\n")
5989
0
SLANG_RAW("__intrinsic_op(")
5990
0
SLANG_SPLICE(kIROp_ByteAddressBufferLoad
5991
0
)
5992
0
SLANG_RAW(")\n")
5993
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer_rw)]\n")
5994
0
SLANG_RAW("T __byteAddressBufferLoad<T>(RasterizerOrderedByteAddressBuffer buffer, uint offset, uint alignment);\n")
5995
0
SLANG_RAW("\n")
5996
0
SLANG_RAW("__intrinsic_op(")
5997
0
SLANG_SPLICE(kIROp_ByteAddressBufferStore
5998
0
)
5999
0
SLANG_RAW(")\n")
6000
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer_rw)]\n")
6001
0
SLANG_RAW("void __byteAddressBufferStore<T>(RWByteAddressBuffer buffer, uint offset, uint alignment, T value);\n")
6002
0
SLANG_RAW("\n")
6003
0
SLANG_RAW("__intrinsic_op(")
6004
0
SLANG_SPLICE(kIROp_ByteAddressBufferStore
6005
0
)
6006
0
SLANG_RAW(")\n")
6007
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, byteaddressbuffer_rw)]\n")
6008
0
SLANG_RAW("void __byteAddressBufferStore<T>(RasterizerOrderedByteAddressBuffer buffer, uint offset, uint alignment, T value);\n")
6009
0
SLANG_RAW("\n")
6010
0
SLANG_RAW("__intrinsic_op(")
6011
0
SLANG_SPLICE(kIROp_GetUntypedBufferPtr
6012
0
)
6013
0
SLANG_RAW(")\n")
6014
0
SLANG_RAW("[require(spirv, byteaddressbuffer)]\n")
6015
0
SLANG_RAW("Ptr<uint[]> __getByteAddressBufferPtr(ByteAddressBuffer buffer);\n")
6016
0
SLANG_RAW("\n")
6017
0
SLANG_RAW("__intrinsic_op(")
6018
0
SLANG_SPLICE(kIROp_GetUntypedBufferPtr
6019
0
)
6020
0
SLANG_RAW(")\n")
6021
0
SLANG_RAW("[require(spirv, byteaddressbuffer_rw)]\n")
6022
0
SLANG_RAW("Ptr<uint[]> __getByteAddressBufferPtr(RWByteAddressBuffer buffer);\n")
6023
0
SLANG_RAW("\n")
6024
0
SLANG_RAW("__intrinsic_op(")
6025
0
SLANG_SPLICE(kIROp_GetStructuredBufferPtr
6026
0
)
6027
0
SLANG_RAW(")\n")
6028
0
SLANG_RAW("[require(spirv, structuredbuffer)]\n")
6029
0
SLANG_RAW("Ptr<T[]> __getStructuredBufferPtr<T>(StructuredBuffer<T> buffer);\n")
6030
0
SLANG_RAW("\n")
6031
0
SLANG_RAW("__intrinsic_op(")
6032
0
SLANG_SPLICE(kIROp_GetStructuredBufferPtr
6033
0
)
6034
0
SLANG_RAW(")\n")
6035
0
SLANG_RAW("[require(spirv, structuredbuffer_rw)]\n")
6036
0
SLANG_RAW("Ptr<T[]> __getStructuredBufferPtr<T>(RWStructuredBuffer<T> buffer);\n")
6037
0
SLANG_RAW("\n")
6038
0
SLANG_RAW("/**\n")
6039
0
SLANG_RAW("Represents an opaque handle to a read-only structured buffer allocated in global memory.\n")
6040
0
SLANG_RAW("A structured buffer can be viewed as an array of the specified element type.\n")
6041
0
SLANG_RAW("@param T The element type of the buffer.\n")
6042
0
SLANG_RAW("@param L The memory layout of the buffer.\n")
6043
0
SLANG_RAW("@remarks\n")
6044
0
SLANG_RAW("The `L` generic parameter is used to specify the memory layout of the buffer when\n")
6045
0
SLANG_RAW("generating SPIRV.\n")
6046
0
SLANG_RAW("`L` must be one of `DefaultDataLayout`, `Std140DataLayout`, `Std430DataLayout` or `ScalarDataLayout`.\n")
6047
0
SLANG_RAW("The default value is `DefaultDataLayout`.\n")
6048
0
SLANG_RAW("When generating code for other targets, this parameter is ignored and has no effect on the generated code.\n")
6049
0
SLANG_RAW("@see `RWStructuredBuffer`, `AppendStructuredBuffer`, `ConsumeStructuredBuffer`, `RasterizerOrderedStructuredBuffer`.\n")
6050
0
SLANG_RAW("@category buffer_types Buffer types\n")
6051
0
SLANG_RAW("**/\n")
6052
0
SLANG_RAW("__generic<T, L:IBufferDataLayout=DefaultDataLayout>\n")
6053
0
SLANG_RAW("__magic_type(HLSLStructuredBufferType)\n")
6054
0
SLANG_RAW("__intrinsic_type(")
6055
0
SLANG_SPLICE(kIROp_HLSLStructuredBufferType
6056
0
)
6057
0
SLANG_RAW(")\n")
6058
0
SLANG_RAW("struct StructuredBuffer\n")
6059
0
SLANG_RAW("{\n")
6060
0
SLANG_RAW("\n")
6061
0
SLANG_RAW("    /// Get the dimensions of the buffer.\n")
6062
0
SLANG_RAW("    /// @param numStructs The number of structures in the buffer.\n")
6063
0
SLANG_RAW("    /// @param stride The stride, in bytes, of each structure element.\n")
6064
0
SLANG_RAW("    [__readNone]\n")
6065
0
SLANG_RAW("    [ForceInline]\n")
6066
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer)]\n")
6067
0
SLANG_RAW("    void GetDimensions(\n")
6068
0
SLANG_RAW("        out uint numStructs,\n")
6069
0
SLANG_RAW("        out uint stride)\n")
6070
0
SLANG_RAW("    {\n")
6071
0
SLANG_RAW("        let rs = __structuredBufferGetDimensions(this);\n")
6072
0
SLANG_RAW("        numStructs = rs.x;\n")
6073
0
SLANG_RAW("        stride = rs.y;\n")
6074
0
SLANG_RAW("    }\n")
6075
0
SLANG_RAW("\n")
6076
0
SLANG_RAW("    /// Load a element from the buffer at the specified location.\n")
6077
0
SLANG_RAW("    /// @param TIndex Type of the index.\n")
6078
0
SLANG_RAW("    /// @param location The index of buffer.\n")
6079
0
SLANG_RAW("    /// @param[out] status The status of the operation.\n")
6080
0
SLANG_RAW("    /// @return The element at the specified index.\n")
6081
0
SLANG_RAW("    ///\n")
6082
0
SLANG_RAW("    /// @remarks\n")
6083
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
6084
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
6085
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
6086
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
6087
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
6088
0
SLANG_RAW("    __intrinsic_op(")
6089
0
SLANG_SPLICE(kIROp_StructuredBufferLoad
6090
0
)
6091
0
SLANG_RAW(")\n")
6092
0
SLANG_RAW("    [__readNone]\n")
6093
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, structuredbuffer)]\n")
6094
0
SLANG_RAW("    T Load<TIndex : __BuiltinIntegerType>(TIndex location);\n")
6095
0
SLANG_RAW("\n")
6096
0
SLANG_RAW("    __intrinsic_op(")
6097
0
SLANG_SPLICE(kIROp_StructuredBufferLoadStatus
6098
0
)
6099
0
SLANG_RAW(")\n")
6100
0
SLANG_RAW("    [require(hlsl, structuredbuffer)]\n")
6101
0
SLANG_RAW("    T Load<TIndex : __BuiltinIntegerType>(TIndex location, out uint status);\n")
6102
0
SLANG_RAW("\n")
6103
0
SLANG_RAW("    /// Load a element from the buffer at the specified location.\n")
6104
0
SLANG_RAW("    /// @param TIndex Type of the index.\n")
6105
0
SLANG_RAW("    /// @param index The index of buffer.\n")
6106
0
SLANG_RAW("    /// @return The element at the specified index.\n")
6107
0
SLANG_RAW("    __generic<TIndex : __BuiltinIntegerType>\n")
6108
0
SLANG_RAW("    __subscript(TIndex index) -> T\n")
6109
0
SLANG_RAW("    {\n")
6110
0
SLANG_RAW("        [__readNone]\n")
6111
0
SLANG_RAW("        __intrinsic_op(")
6112
0
SLANG_SPLICE(kIROp_StructuredBufferLoad
6113
0
)
6114
0
SLANG_RAW(")\n")
6115
0
SLANG_RAW("        [require(cpp_cuda_glsl_hlsl_spirv, structuredbuffer)]\n")
6116
0
SLANG_RAW("        get;\n")
6117
0
SLANG_RAW("    };\n")
6118
0
SLANG_RAW("};\n")
6119
0
SLANG_RAW("\n")
6120
0
SLANG_RAW("/**\n")
6121
0
SLANG_RAW("Represents an opaque handle to a consume structured buffer allocated in global memory.\n")
6122
0
SLANG_RAW("A structured buffer can be viewed as an array of the specified element type.\n")
6123
0
SLANG_RAW("An append structure buffer internally maintains an atomic counter to keep track of the number of elements in the buffer,\n")
6124
0
SLANG_RAW("and provide an atomic operation to append a new element to the buffer.\n")
6125
0
SLANG_RAW("@param T The element type of the buffer.\n")
6126
0
SLANG_RAW("@param L The memory layout of the buffer.\n")
6127
0
SLANG_RAW("@remarks\n")
6128
0
SLANG_RAW("This type is supported natively when targeting HLSL.\n")
6129
0
SLANG_RAW("When generating code for other targets, this type is translated into a pair or an ordinary `StructuredBuffer` and\n")
6130
0
SLANG_RAW("a separate `RWStructuredBuffer` that holds the atomic counter.\n")
6131
0
SLANG_RAW("The `L` generic parameter is used to specify the memory layout of the buffer when\n")
6132
0
SLANG_RAW("generating SPIRV.\n")
6133
0
SLANG_RAW("`L` must be one of `DefaultDataLayout`, `Std140DataLayout`, `Std430DataLayout` or `ScalarDataLayout`.\n")
6134
0
SLANG_RAW("The default value is `DefaultDataLayout`.\n")
6135
0
SLANG_RAW("When generating code for other targets, this parameter is ignored and has no effect on the generated code.\n")
6136
0
SLANG_RAW("@see `StructuredBuffer`, `AppendStructuredBuffer`, `RWStructuredBuffer`, `RasterizerOrderedStructuredBuffer`.\n")
6137
0
SLANG_RAW("@category buffer_types\n")
6138
0
SLANG_RAW("*/\n")
6139
0
SLANG_RAW("__generic<T, L:IBufferDataLayout=DefaultDataLayout>\n")
6140
0
SLANG_RAW("__magic_type(HLSLConsumeStructuredBufferType)\n")
6141
0
SLANG_RAW("__intrinsic_type(")
6142
0
SLANG_SPLICE(kIROp_HLSLConsumeStructuredBufferType
6143
0
)
6144
0
SLANG_RAW(")\n")
6145
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, consumestructuredbuffer)]\n")
6146
0
SLANG_RAW("struct ConsumeStructuredBuffer\n")
6147
0
SLANG_RAW("{\n")
6148
0
SLANG_RAW("    /// Reading the element at the end of the buffer indicated by the associated atomic counter\n")
6149
0
SLANG_RAW("    /// and decrement the builtin atomic counter by 1.\n")
6150
0
SLANG_RAW("    ///@return The element read from the buffer, it can be a structure.\n")
6151
0
SLANG_RAW("    __intrinsic_op(")
6152
0
SLANG_SPLICE(kIROp_StructuredBufferConsume
6153
0
)
6154
0
SLANG_RAW(")\n")
6155
0
SLANG_RAW("    T Consume();\n")
6156
0
SLANG_RAW("\n")
6157
0
SLANG_RAW("    ///Gets the dimensions of the resource.\n")
6158
0
SLANG_RAW("    ///@param[out] numStructs The number of structures in the buffer.\n")
6159
0
SLANG_RAW("    ///@param[out] stride The stride, in bytes, of each element\n")
6160
0
SLANG_RAW("\n")
6161
0
SLANG_RAW("    [ForceInline]\n")
6162
0
SLANG_RAW("    void GetDimensions(\n")
6163
0
SLANG_RAW("        out uint numStructs,\n")
6164
0
SLANG_RAW("        out uint stride)\n")
6165
0
SLANG_RAW("    {\n")
6166
0
SLANG_RAW("        let result = __structuredBufferGetDimensions(this);\n")
6167
0
SLANG_RAW("        numStructs = result.x;\n")
6168
0
SLANG_RAW("        stride = result.y;\n")
6169
0
SLANG_RAW("    }\n")
6170
0
SLANG_RAW("};\n")
6171
0
SLANG_RAW("\n")
6172
0
SLANG_RAW("__intrinsic_op(")
6173
0
SLANG_SPLICE(kIROp_GetElement
6174
0
)
6175
0
SLANG_RAW(")\n")
6176
0
SLANG_RAW("T __getElement<T, U, I>(U collection, I index);\n")
6177
0
SLANG_RAW("\n")
6178
0
SLANG_RAW("/// @category stage_io Stage IO types\n")
6179
0
SLANG_RAW("__generic<T, let N : int>\n")
6180
0
SLANG_RAW("[require(glsl_hlsl_spirv, geometry)]\n")
6181
0
SLANG_RAW("[require(glsl_hlsl_spirv, hull)]\n")
6182
0
SLANG_RAW("__magic_type(HLSLInputPatchType)\n")
6183
0
SLANG_RAW("__intrinsic_type(")
6184
0
SLANG_SPLICE(kIROp_HLSLInputPatchType
6185
0
)
6186
0
SLANG_RAW(")\n")
6187
0
SLANG_RAW("struct InputPatch\n")
6188
0
SLANG_RAW("{\n")
6189
0
SLANG_RAW("    __generic<TIndex : __BuiltinIntegerType>\n")
6190
0
SLANG_RAW("    __subscript(TIndex index)->T\n")
6191
0
SLANG_RAW("    {\n")
6192
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
6193
0
SLANG_RAW("        get\n")
6194
0
SLANG_RAW("        {\n")
6195
0
SLANG_RAW("            __target_switch\n")
6196
0
SLANG_RAW("            {\n")
6197
0
SLANG_RAW("            case hlsl:\n")
6198
0
SLANG_RAW("                __intrinsic_asm \".operator[]\";\n")
6199
0
SLANG_RAW("            default:\n")
6200
0
SLANG_RAW("                return __getElement<T>(this, index);\n")
6201
0
SLANG_RAW("            }\n")
6202
0
SLANG_RAW("        }\n")
6203
0
SLANG_RAW("    }\n")
6204
0
SLANG_RAW("};\n")
6205
0
SLANG_RAW("\n")
6206
0
SLANG_RAW("/// @category stage_io\n")
6207
0
SLANG_RAW("__generic<T, let N : int>\n")
6208
0
SLANG_RAW("[require(glsl_hlsl_spirv, domain_hull)]\n")
6209
0
SLANG_RAW("__magic_type(HLSLOutputPatchType)\n")
6210
0
SLANG_RAW("__intrinsic_type(")
6211
0
SLANG_SPLICE(kIROp_HLSLOutputPatchType
6212
0
)
6213
0
SLANG_RAW(")\n")
6214
0
SLANG_RAW("struct OutputPatch\n")
6215
0
SLANG_RAW("{\n")
6216
0
SLANG_RAW("    __generic<TIndex : __BuiltinIntegerType>\n")
6217
0
SLANG_RAW("    __subscript(TIndex index)->T\n")
6218
0
SLANG_RAW("    {\n")
6219
0
SLANG_RAW("        [__unsafeForceInlineEarly]\n")
6220
0
SLANG_RAW("        get\n")
6221
0
SLANG_RAW("        {\n")
6222
0
SLANG_RAW("            __target_switch\n")
6223
0
SLANG_RAW("            {\n")
6224
0
SLANG_RAW("            case hlsl:\n")
6225
0
SLANG_RAW("                __intrinsic_asm \".operator[]\";\n")
6226
0
SLANG_RAW("            default:\n")
6227
0
SLANG_RAW("                return __getElement<T>(this, index);\n")
6228
0
SLANG_RAW("            }\n")
6229
0
SLANG_RAW("        }\n")
6230
0
SLANG_RAW("    }\n")
6231
0
SLANG_RAW("};\n")
6232
0
SLANG_RAW("\n")
6233
6234
0
static const struct {
6235
0
    IROp op;
6236
0
    char const* name;
6237
0
} kMutableByteAddressBufferCases[] =
6238
0
{
6239
0
    { kIROp_HLSLRWByteAddressBufferType,                "RWByteAddressBuffer" },
6240
0
    { kIROp_HLSLRasterizerOrderedByteAddressBufferType, "RasterizerOrderedByteAddressBuffer" },
6241
0
};
6242
0
for(auto item : kMutableByteAddressBufferCases) {
6243
0
SLANG_RAW("#line 5121 \"hlsl.meta.slang\"")
6244
0
SLANG_RAW("\n")
6245
0
SLANG_RAW("\n")
6246
0
SLANG_RAW("//@public:\n")
6247
0
SLANG_RAW("/**\n")
6248
0
SLANG_RAW("Represents an opaque handle to a read-write buffer allocated in global memory that is indexed in bytes.\n")
6249
0
SLANG_RAW("This type can be used when working with raw buffers. Raw buffer can be viewed as a bag of bits to\n")
6250
0
SLANG_RAW("which you want raw access, that is, a buffer that you can conveniently access through chunks of one to\n")
6251
0
SLANG_RAW("four 32-bit typeless address values.\n")
6252
0
SLANG_RAW(" @remarks\n")
6253
0
SLANG_RAW("This type is supported natively when targeting HLSL.\n")
6254
0
SLANG_RAW(" @category buffer_types\n")
6255
0
SLANG_RAW("*/\n")
6256
0
SLANG_RAW("__magic_type(HLSL")
6257
0
SLANG_SPLICE(item.name
6258
0
)
6259
0
SLANG_RAW("Type)\n")
6260
0
SLANG_RAW("__intrinsic_type(")
6261
0
SLANG_SPLICE(item.op
6262
0
)
6263
0
SLANG_RAW(")\n")
6264
0
SLANG_RAW("[require(byteaddressbuffer_rw)]\n")
6265
0
SLANG_RAW("struct ")
6266
0
SLANG_SPLICE(item.name
6267
0
)
6268
0
SLANG_RAW("\n")
6269
0
SLANG_RAW("{\n")
6270
0
SLANG_RAW("    // Note(tfoley): supports all operations from `ByteAddressBuffer`\n")
6271
0
SLANG_RAW("    // TODO(tfoley): can this be made a sub-type?\n")
6272
0
SLANG_RAW("\n")
6273
0
SLANG_RAW("    /// Get the number of bytes in the buffer.\n")
6274
0
SLANG_RAW("    ///@param[out] dim The number of bytes in the buffer.\n")
6275
0
SLANG_RAW("    [ForceInline]\n")
6276
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_spirv_wgsl)]\n")
6277
0
SLANG_RAW("    void GetDimensions(out uint dim)\n")
6278
0
SLANG_RAW("    {\n")
6279
0
SLANG_RAW("        __target_switch\n")
6280
0
SLANG_RAW("        {\n")
6281
0
SLANG_RAW("        case cpp: __intrinsic_asm \".GetDimensions\";\n")
6282
0
SLANG_RAW("        case cuda: __intrinsic_asm \".GetDimensions\";\n")
6283
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetDimensions\";\n")
6284
0
SLANG_RAW("        default:\n")
6285
0
SLANG_RAW("            dim = __structuredBufferGetDimensions(__getEquivalentStructuredBuffer<uint>(this)).x*4;\n")
6286
0
SLANG_RAW("        }\n")
6287
0
SLANG_RAW("    }\n")
6288
0
SLANG_RAW("\n")
6289
0
SLANG_RAW("    /// Load a 32-bit unsigned integer or value with type of `T` from the buffer at the specified location.\n")
6290
0
SLANG_RAW("    ///@param T The type of the value to load from the buffer.\n")
6291
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of 4.\n")
6292
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
6293
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
6294
0
SLANG_RAW("    ///@return The value loaded from the buffer.\n")
6295
0
SLANG_RAW("    ///\n")
6296
0
SLANG_RAW("    ///@remarks\n")
6297
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
6298
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
6299
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
6300
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
6301
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
6302
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
6303
0
SLANG_RAW("    [__NoSideEffect]\n")
6304
0
SLANG_RAW("    [ForceInline]\n")
6305
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6306
0
SLANG_RAW("    uint Load(int location)\n")
6307
0
SLANG_RAW("    {\n")
6308
0
SLANG_RAW("        __target_switch\n")
6309
0
SLANG_RAW("        {\n")
6310
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
6311
0
SLANG_RAW("        default:\n")
6312
0
SLANG_RAW("            return __byteAddressBufferLoad<uint>(this, uint(location), 0);\n")
6313
0
SLANG_RAW("        }\n")
6314
0
SLANG_RAW("    }\n")
6315
0
SLANG_RAW("\n")
6316
0
SLANG_RAW("    [__NoSideEffect]\n")
6317
0
SLANG_RAW("    [ForceInline]\n")
6318
0
SLANG_RAW("    [require(hlsl)]\n")
6319
0
SLANG_RAW("    uint Load(int location, out uint status)\n")
6320
0
SLANG_RAW("    {\n")
6321
0
SLANG_RAW("        __target_switch\n")
6322
0
SLANG_RAW("        {\n")
6323
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
6324
0
SLANG_RAW("        }\n")
6325
0
SLANG_RAW("    }\n")
6326
0
SLANG_RAW("\n")
6327
0
SLANG_RAW("    /// Load two 32-bit unsigned integers from the buffer at the specified location\n")
6328
0
SLANG_RAW("    /// with additional alignment.\n")
6329
0
SLANG_RAW("    ///@param location The input address in bytes.\n")
6330
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
6331
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
6332
0
SLANG_RAW("    ///@return Two 32-bit unsigned integers loaded from the buffer.\n")
6333
0
SLANG_RAW("    ///\n")
6334
0
SLANG_RAW("    ///@remarks\n")
6335
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
6336
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
6337
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
6338
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
6339
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
6340
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
6341
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
6342
0
SLANG_RAW("    [__NoSideEffect]\n")
6343
0
SLANG_RAW("    [ForceInline]\n")
6344
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6345
0
SLANG_RAW("    uint2 Load2(uint location)\n")
6346
0
SLANG_RAW("    {\n")
6347
0
SLANG_RAW("        __target_switch\n")
6348
0
SLANG_RAW("        {\n")
6349
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
6350
0
SLANG_RAW("        default:\n")
6351
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, 0);\n")
6352
0
SLANG_RAW("        }\n")
6353
0
SLANG_RAW("    }\n")
6354
0
SLANG_RAW("\n")
6355
0
SLANG_RAW("    [__NoSideEffect]\n")
6356
0
SLANG_RAW("    [ForceInline]\n")
6357
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6358
0
SLANG_RAW("    uint2 Load2Aligned(uint location, uint alignment)\n")
6359
0
SLANG_RAW("    {\n")
6360
0
SLANG_RAW("        __target_switch\n")
6361
0
SLANG_RAW("        {\n")
6362
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
6363
0
SLANG_RAW("        default:\n")
6364
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, alignment);\n")
6365
0
SLANG_RAW("        }\n")
6366
0
SLANG_RAW("    }\n")
6367
0
SLANG_RAW("\n")
6368
0
SLANG_RAW("    /// Load two 32-bit unsigned integers from the buffer at the specified location with alignment\n")
6369
0
SLANG_RAW("    /// of `uint2`, which is 8.\n")
6370
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of alignment of 8.\n")
6371
0
SLANG_RAW("    ///@return `uint2` Two 32-bit unsigned integers loaded from the buffer.\n")
6372
0
SLANG_RAW("    [__NoSideEffect]\n")
6373
0
SLANG_RAW("    [ForceInline]\n")
6374
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6375
0
SLANG_RAW("    uint2 Load2Aligned(uint location)\n")
6376
0
SLANG_RAW("    {\n")
6377
0
SLANG_RAW("        __target_switch\n")
6378
0
SLANG_RAW("        {\n")
6379
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
6380
0
SLANG_RAW("        default:\n")
6381
0
SLANG_RAW("            return __byteAddressBufferLoad<uint2>(this, location, __naturalStrideOf<uint2>());\n")
6382
0
SLANG_RAW("        }\n")
6383
0
SLANG_RAW("    }\n")
6384
0
SLANG_RAW("\n")
6385
0
SLANG_RAW("    [__NoSideEffect]\n")
6386
0
SLANG_RAW("    [ForceInline]\n")
6387
0
SLANG_RAW("    [require(hlsl)]\n")
6388
0
SLANG_RAW("    uint2 Load2(uint location, out uint status)\n")
6389
0
SLANG_RAW("    {\n")
6390
0
SLANG_RAW("        __target_switch\n")
6391
0
SLANG_RAW("        {\n")
6392
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load2\";\n")
6393
0
SLANG_RAW("        }\n")
6394
0
SLANG_RAW("    }\n")
6395
0
SLANG_RAW("\n")
6396
0
SLANG_RAW("    /// Load three 32-bit unsigned integers from the buffer at the specified location.\n")
6397
0
SLANG_RAW("    ///@param location The input address in bytes, which must be a multiple of 4.\n")
6398
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
6399
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
6400
0
SLANG_RAW("    ///@return `uint3` Three 32-bit unsigned integer value loaded from the buffer.\n")
6401
0
SLANG_RAW("    ///\n")
6402
0
SLANG_RAW("    ///@remarks\n")
6403
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
6404
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
6405
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
6406
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
6407
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
6408
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
6409
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
6410
0
SLANG_RAW("    [__NoSideEffect]\n")
6411
0
SLANG_RAW("    [ForceInline]\n")
6412
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6413
0
SLANG_RAW("    uint3 Load3(uint location)\n")
6414
0
SLANG_RAW("    {\n")
6415
0
SLANG_RAW("        __target_switch\n")
6416
0
SLANG_RAW("        {\n")
6417
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
6418
0
SLANG_RAW("        default:\n")
6419
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, 0);\n")
6420
0
SLANG_RAW("        }\n")
6421
0
SLANG_RAW("    }\n")
6422
0
SLANG_RAW("\n")
6423
0
SLANG_RAW("    [__NoSideEffect]\n")
6424
0
SLANG_RAW("    [ForceInline]\n")
6425
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6426
0
SLANG_RAW("    uint3 Load3Aligned(uint location, uint alignment)\n")
6427
0
SLANG_RAW("    {\n")
6428
0
SLANG_RAW("        __target_switch\n")
6429
0
SLANG_RAW("        {\n")
6430
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
6431
0
SLANG_RAW("        default:\n")
6432
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, alignment);\n")
6433
0
SLANG_RAW("        }\n")
6434
0
SLANG_RAW("    }\n")
6435
0
SLANG_RAW("\n")
6436
0
SLANG_RAW("    /// Load three 32-bit unsigned integers from the buffer at the specified location with alignment\n")
6437
0
SLANG_RAW("    /// of `uint3`, which is 12.\n")
6438
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 12.\n")
6439
0
SLANG_RAW("    ///@return `uint3` Three 32-bit unsigned integer value loaded from the buffer.\n")
6440
0
SLANG_RAW("    [__NoSideEffect]\n")
6441
0
SLANG_RAW("    [ForceInline]\n")
6442
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6443
0
SLANG_RAW("    uint3 Load3Aligned(uint location)\n")
6444
0
SLANG_RAW("    {\n")
6445
0
SLANG_RAW("        __target_switch\n")
6446
0
SLANG_RAW("        {\n")
6447
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
6448
0
SLANG_RAW("        default:\n")
6449
0
SLANG_RAW("            return __byteAddressBufferLoad<uint3>(this, location, __naturalStrideOf<uint3>());\n")
6450
0
SLANG_RAW("        }\n")
6451
0
SLANG_RAW("    }\n")
6452
0
SLANG_RAW("\n")
6453
0
SLANG_RAW("    [__NoSideEffect]\n")
6454
0
SLANG_RAW("    [ForceInline]\n")
6455
0
SLANG_RAW("    [require(hlsl)]\n")
6456
0
SLANG_RAW("    uint3 Load3(uint location, out uint status)\n")
6457
0
SLANG_RAW("    {\n")
6458
0
SLANG_RAW("        __target_switch\n")
6459
0
SLANG_RAW("        {\n")
6460
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load3\";\n")
6461
0
SLANG_RAW("        }\n")
6462
0
SLANG_RAW("    }\n")
6463
0
SLANG_RAW("\n")
6464
0
SLANG_RAW("    /// Load four 32-bit unsigned integers from the buffer at the specified location.\n")
6465
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 4.\n")
6466
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
6467
0
SLANG_RAW("    ///@param[out] status The status of the operation.\n")
6468
0
SLANG_RAW("    ///@return `uint4` Four 32-bit unsigned integer value loaded from the buffer.\n")
6469
0
SLANG_RAW("    ///\n")
6470
0
SLANG_RAW("    ///@remarks\n")
6471
0
SLANG_RAW("    /// This function only supports when targeting HLSL.\n")
6472
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
6473
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
6474
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
6475
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
6476
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
6477
0
SLANG_RAW("    [__NoSideEffect]\n")
6478
0
SLANG_RAW("    [ForceInline]\n")
6479
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6480
0
SLANG_RAW("    uint4 Load4(uint location)\n")
6481
0
SLANG_RAW("    {\n")
6482
0
SLANG_RAW("        __target_switch\n")
6483
0
SLANG_RAW("        {\n")
6484
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
6485
0
SLANG_RAW("        default:\n")
6486
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, 0);\n")
6487
0
SLANG_RAW("        }\n")
6488
0
SLANG_RAW("    }\n")
6489
0
SLANG_RAW("\n")
6490
0
SLANG_RAW("    [__NoSideEffect]\n")
6491
0
SLANG_RAW("    [ForceInline]\n")
6492
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6493
0
SLANG_RAW("    uint4 Load4Aligned(uint location, uint alignment)\n")
6494
0
SLANG_RAW("    {\n")
6495
0
SLANG_RAW("        __target_switch\n")
6496
0
SLANG_RAW("        {\n")
6497
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
6498
0
SLANG_RAW("        default:\n")
6499
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, alignment);\n")
6500
0
SLANG_RAW("        }\n")
6501
0
SLANG_RAW("    }\n")
6502
0
SLANG_RAW("\n")
6503
0
SLANG_RAW("    /// Load four 32-bit unsigned integers from the buffer at the specified location with alignment\n")
6504
0
SLANG_RAW("    /// of `uint4`, which is 16.\n")
6505
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of alignment of 16.\n")
6506
0
SLANG_RAW("    ///@return `uint4` Four 32-bit unsigned integer value loaded from the buffer.\n")
6507
0
SLANG_RAW("    [__NoSideEffect]\n")
6508
0
SLANG_RAW("    [ForceInline]\n")
6509
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6510
0
SLANG_RAW("    uint4 Load4Aligned(uint location)\n")
6511
0
SLANG_RAW("    {\n")
6512
0
SLANG_RAW("        __target_switch\n")
6513
0
SLANG_RAW("        {\n")
6514
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
6515
0
SLANG_RAW("        default:\n")
6516
0
SLANG_RAW("            return __byteAddressBufferLoad<uint4>(this, location, __naturalStrideOf<uint4>());\n")
6517
0
SLANG_RAW("        }\n")
6518
0
SLANG_RAW("    }\n")
6519
0
SLANG_RAW("\n")
6520
0
SLANG_RAW("    [__NoSideEffect]\n")
6521
0
SLANG_RAW("    [ForceInline]\n")
6522
0
SLANG_RAW("    [require(hlsl)]\n")
6523
0
SLANG_RAW("    uint4 Load4(uint location, out uint status)\n")
6524
0
SLANG_RAW("    {\n")
6525
0
SLANG_RAW("        __target_switch\n")
6526
0
SLANG_RAW("        {\n")
6527
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load4\";\n")
6528
0
SLANG_RAW("        }\n")
6529
0
SLANG_RAW("    }\n")
6530
0
SLANG_RAW("\n")
6531
0
SLANG_RAW("    [__NoSideEffect]\n")
6532
0
SLANG_RAW("    [ForceInline]\n")
6533
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6534
0
SLANG_RAW("    T Load<T>(uint location)\n")
6535
0
SLANG_RAW("    {\n")
6536
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, 0);\n")
6537
0
SLANG_RAW("    }\n")
6538
0
SLANG_RAW("\n")
6539
0
SLANG_RAW("    [__NoSideEffect]\n")
6540
0
SLANG_RAW("    [ForceInline]\n")
6541
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6542
0
SLANG_RAW("    T LoadAligned<T>(uint location, uint alignment)\n")
6543
0
SLANG_RAW("    {\n")
6544
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, alignment);\n")
6545
0
SLANG_RAW("    }\n")
6546
0
SLANG_RAW("\n")
6547
0
SLANG_RAW("    /// Load an element with type `T` from the buffer at the specified location with alignment of `T`.\n")
6548
0
SLANG_RAW("    ///@param location The input address in bytes which must be a multiple of size of `T`.\n")
6549
0
SLANG_RAW("    ///@return T value with type `T` loaded from the buffer.\n")
6550
0
SLANG_RAW("    ///@remarks\n")
6551
0
SLANG_RAW("    ///Currently, this function only supports when `T` is scalar, vector, or matrix type.\n")
6552
0
SLANG_RAW("    [__NoSideEffect]\n")
6553
0
SLANG_RAW("    [ForceInline]\n")
6554
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
6555
0
SLANG_RAW("    T LoadAligned<T>(uint location)\n")
6556
0
SLANG_RAW("    {\n")
6557
0
SLANG_RAW("        return __byteAddressBufferLoad<T>(this, location, __naturalStrideOf<T>());\n")
6558
0
SLANG_RAW("    }\n")
6559
0
SLANG_RAW("\n")
6560
6561
0
    struct BufferAtomicOps
6562
0
    {
6563
0
        const char* name;
6564
0
        const char* internalName;
6565
0
    };
6566
0
    const BufferAtomicOps bufferAtomicOps[] = {
6567
0
        {"Max", "max"},
6568
0
        {"Min", "min"},
6569
0
        {"Add", "add"},
6570
0
        {"And", "and"},
6571
0
        {"Or", "or"},
6572
0
        {"Xor", "xor"},
6573
0
        {"Exchange", "exchange"}
6574
0
    };
6575
0
    if (item.op == kIROp_HLSLRWByteAddressBufferType)
6576
0
    {
6577
0
SLANG_RAW("#line 5445 \"hlsl.meta.slang\"")
6578
0
SLANG_RAW("\n")
6579
0
SLANG_RAW("\n")
6580
0
SLANG_RAW("    // float32 and int64 atomic support. This is a Slang specific extension, it uses\n")
6581
0
SLANG_RAW("    // GL_EXT_shader_atomic_float on Vulkan\n")
6582
0
SLANG_RAW("    // NvAPI support on DX\n")
6583
0
SLANG_RAW("    // NOTE! To use this feature on HLSL based targets the path to 'nvHLSLExtns.h' from the NvAPI SDK must\n")
6584
0
SLANG_RAW("    // be set. That this include will be added to the *output* that is passed to a downstram compiler.\n")
6585
0
SLANG_RAW("    // Also note that you *can* include NVAPI headers in your Slang source, and directly use NVAPI functions\n")
6586
0
SLANG_RAW("    // Directly using NVAPI functions does *not* add the #include on the output\n")
6587
0
SLANG_RAW("    // Finally note you can *mix* NVAPI direct calls, and use of NVAPI intrinsics below. This doesn't cause\n")
6588
0
SLANG_RAW("    // any clashes, as Slang will emit any NVAPI function it parsed (say via a include in Slang source) with\n")
6589
0
SLANG_RAW("    // unique functions.\n")
6590
0
SLANG_RAW("    //\n")
6591
0
SLANG_RAW("    // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_EXT_shader_atomic_float\n")
6592
0
SLANG_RAW("    // https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/EXT/SPV_EXT_shader_atomic_float_add.html\n")
6593
0
SLANG_RAW("\n")
6594
0
SLANG_RAW("    // F32 Add\n")
6595
0
SLANG_RAW("\n")
6596
0
SLANG_RAW("    /// Perform a 32-bit floating point atomic add operation at `byteAddress`.\n")
6597
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic add operation.\n")
6598
0
SLANG_RAW("    /// @param valueToAdd The value to add to the value at `byteAddress`.\n")
6599
0
SLANG_RAW("    /// @param originalValue The original value at `byteAddress` before the add operation.\n")
6600
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicFAdd`. For HLSL, this function translates to an NVAPI call\n")
6601
0
SLANG_RAW("    /// due to lack of native HLSL intrinsic for floating point atomic add. For CUDA, this function\n")
6602
0
SLANG_RAW("    /// maps to `atomicAdd`.\n")
6603
0
SLANG_RAW("    __cuda_sm_version(2.0)\n")
6604
0
SLANG_RAW("    [__requiresNVAPI]\n")
6605
0
SLANG_RAW("    [ForceInline]\n")
6606
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_nvapi_cuda_metal_float1)]\n")
6607
0
SLANG_RAW("    void InterlockedAddF32(uint byteAddress, float valueToAdd, out float originalValue)\n")
6608
0
SLANG_RAW("    {\n")
6609
0
SLANG_RAW("        __target_switch\n")
6610
0
SLANG_RAW("        {\n")
6611
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($3 = NvInterlockedAddFp32($0, $1, $2))\";\n")
6612
0
SLANG_RAW("        case cuda: __intrinsic_asm \"(*$3 = atomicAdd($0._getPtrAt<float>($1), $2))\";\n")
6613
0
SLANG_RAW("        default:\n")
6614
0
SLANG_RAW("            {\n")
6615
0
SLANG_RAW("                let buf = __getEquivalentStructuredBuffer<float>(this);\n")
6616
0
SLANG_RAW("                originalValue = __atomic_add(buf[byteAddress / 4], valueToAdd);\n")
6617
0
SLANG_RAW("                return;\n")
6618
0
SLANG_RAW("            }\n")
6619
0
SLANG_RAW("        }\n")
6620
0
SLANG_RAW("    }\n")
6621
0
SLANG_RAW("\n")
6622
0
SLANG_RAW("    [require(cuda, cuda_sm_6_0)]\n")
6623
0
SLANG_RAW("    [require(spirv, spvAtomicFloat64AddEXT)]\n")
6624
0
SLANG_RAW("    void InterlockedAddF64(uint byteAddress, double valueToAdd, out double originalValue)\n")
6625
0
SLANG_RAW("    {\n")
6626
0
SLANG_RAW("        __target_switch\n")
6627
0
SLANG_RAW("        {\n")
6628
0
SLANG_RAW("        case cuda: __intrinsic_asm \"(*$3 = atomicAdd($0._getPtrAt<double>($1), $2))\";\n")
6629
0
SLANG_RAW("        default:\n")
6630
0
SLANG_RAW("            {\n")
6631
0
SLANG_RAW("                let buf = __getEquivalentStructuredBuffer<double>(this);\n")
6632
0
SLANG_RAW("                originalValue = __atomic_add(buf[byteAddress / 8], valueToAdd);\n")
6633
0
SLANG_RAW("                return;\n")
6634
0
SLANG_RAW("            }\n")
6635
0
SLANG_RAW("        }\n")
6636
0
SLANG_RAW("    }\n")
6637
0
SLANG_RAW("    // FP16x2\n")
6638
0
SLANG_RAW("\n")
6639
0
SLANG_RAW("    ///@internal\n")
6640
0
SLANG_RAW("    /// Maps to the `NvInterlockedAddFp16x2` NVAPI function.\n")
6641
0
SLANG_RAW("    /// Perform 2 16-bit floating point atomic add operations at `byteAddress`.\n")
6642
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic add operation.\n")
6643
0
SLANG_RAW("    /// @param fp16x2Value Two 16-bit floating point values are packed into a 32-bit unsigned integer.\n")
6644
0
SLANG_RAW("    /// @return The 2 16-bit floating point values packed into a 32-bit unsigned integer.\n")
6645
0
SLANG_RAW("    [__requiresNVAPI]\n")
6646
0
SLANG_RAW("    [ForceInline]\n")
6647
0
SLANG_RAW("    [require(cuda_hlsl_spirv)]\n")
6648
0
SLANG_RAW("    uint _NvInterlockedAddFp16x2(uint byteAddress, uint fp16x2Value)\n")
6649
0
SLANG_RAW("    {\n")
6650
0
SLANG_RAW("        __target_switch\n")
6651
0
SLANG_RAW("        {\n")
6652
0
SLANG_RAW("        case hlsl:\n")
6653
0
SLANG_RAW("            __intrinsic_asm \"NvInterlockedAddFp16x2($0, $1, $2)\";\n")
6654
0
SLANG_RAW("        default:\n")
6655
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<half2>(this);\n")
6656
0
SLANG_RAW("            return bit_cast<uint>(__atomic_add(buf[byteAddress / 4], bit_cast<half2>(fp16x2Value)));\n")
6657
0
SLANG_RAW("        }\n")
6658
0
SLANG_RAW("    }\n")
6659
0
SLANG_RAW("\n")
6660
0
SLANG_RAW("\n")
6661
0
SLANG_RAW("    /// Perform a 16-bit floating point atomic add operation at `byteAddress`.\n")
6662
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic add operation.\n")
6663
0
SLANG_RAW("    /// @param value The value to add to the value at `byteAddress`.\n")
6664
0
SLANG_RAW("    /// @param originalValue The original value at `byteAddress` before the add operation.\n")
6665
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicFAdd` and requires `SPV_EXT_shader_atomic_float16_add` extension.\n")
6666
0
SLANG_RAW("    ///\n")
6667
0
SLANG_RAW("    /// For HLSL, this function translates to an NVAPI call\n")
6668
0
SLANG_RAW("    /// due to lack of native HLSL intrinsic for floating point atomic add. For CUDA, this function\n")
6669
0
SLANG_RAW("    /// maps to `atomicAdd`.\n")
6670
0
SLANG_RAW("    [__requiresNVAPI]\n")
6671
0
SLANG_RAW("    [ForceInline]\n")
6672
0
SLANG_RAW("    [require(sm_5_0)]\n")
6673
0
SLANG_RAW("    void InterlockedAddF16(uint byteAddress, half value, out half originalValue)\n")
6674
0
SLANG_RAW("    {\n")
6675
0
SLANG_RAW("        __target_switch\n")
6676
0
SLANG_RAW("        {\n")
6677
0
SLANG_RAW("        case hlsl:\n")
6678
0
SLANG_RAW("            if ((byteAddress & 2) == 0)\n")
6679
0
SLANG_RAW("            {\n")
6680
0
SLANG_RAW("                uint packedInput = asuint16(value);\n")
6681
0
SLANG_RAW("                originalValue = asfloat16((uint16_t)_NvInterlockedAddFp16x2(byteAddress, packedInput));\n")
6682
0
SLANG_RAW("            }\n")
6683
0
SLANG_RAW("            else\n")
6684
0
SLANG_RAW("            {\n")
6685
0
SLANG_RAW("                byteAddress = byteAddress & ~3;\n")
6686
0
SLANG_RAW("                uint packedInput = ((uint)asuint16(value)) << 16;\n")
6687
0
SLANG_RAW("                originalValue = asfloat16((uint16_t)(_NvInterlockedAddFp16x2(byteAddress, packedInput) >> 16));\n")
6688
0
SLANG_RAW("            }\n")
6689
0
SLANG_RAW("            return;\n")
6690
0
SLANG_RAW("        default:\n")
6691
0
SLANG_RAW("            {\n")
6692
0
SLANG_RAW("                let buf = __getEquivalentStructuredBuffer<half>(this);\n")
6693
0
SLANG_RAW("                originalValue = __atomic_add(buf[byteAddress/2], value);\n")
6694
0
SLANG_RAW("                return;\n")
6695
0
SLANG_RAW("            }\n")
6696
0
SLANG_RAW("        }\n")
6697
0
SLANG_RAW("    }\n")
6698
0
SLANG_RAW("\n")
6699
0
SLANG_RAW("    /// Perform a 16-bit floating point atomic add operation at `byteAddress` through emulation using `half2` atomics.\n")
6700
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic add operation.\n")
6701
0
SLANG_RAW("    /// @param value The value to add to the value at `byteAddress`.\n")
6702
0
SLANG_RAW("    /// @param originalValue The original value at `byteAddress` before the add operation.\n")
6703
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicFAdd` on a `half2` vector with the correct part set to `value`\n")
6704
0
SLANG_RAW("    /// and the remaining part set to 0. This requires the `AtomicFloat16VectorNV` capability introduced by the `SPV_NV_shader_atomic_fp16_vector`\n")
6705
0
SLANG_RAW("    /// extension.\n")
6706
0
SLANG_RAW("    ///\n")
6707
0
SLANG_RAW("    /// For HLSL, this function translates to an equivalent NVAPI call\n")
6708
0
SLANG_RAW("    /// due to lack of native HLSL intrinsic for floating point atomic add. For CUDA, this function\n")
6709
0
SLANG_RAW("    /// maps to `atomicAdd`.\n")
6710
0
SLANG_RAW("    [__requiresNVAPI]\n")
6711
0
SLANG_RAW("    [ForceInline]\n")
6712
0
SLANG_RAW("    [require(sm_5_0)]\n")
6713
0
SLANG_RAW("    void InterlockedAddF16Emulated(uint byteAddress, half value, out half originalValue)\n")
6714
0
SLANG_RAW("    {\n")
6715
0
SLANG_RAW("        __target_switch\n")
6716
0
SLANG_RAW("        {\n")
6717
0
SLANG_RAW("        case hlsl:\n")
6718
0
SLANG_RAW("            if ((byteAddress & 2) == 0)\n")
6719
0
SLANG_RAW("            {\n")
6720
0
SLANG_RAW("                uint packedInput = asuint16(value);\n")
6721
0
SLANG_RAW("                originalValue = asfloat16((uint16_t)_NvInterlockedAddFp16x2(byteAddress, packedInput));\n")
6722
0
SLANG_RAW("            }\n")
6723
0
SLANG_RAW("            else\n")
6724
0
SLANG_RAW("            {\n")
6725
0
SLANG_RAW("                byteAddress = byteAddress & ~3;\n")
6726
0
SLANG_RAW("                uint packedInput = ((uint)asuint16(value)) << 16;\n")
6727
0
SLANG_RAW("                originalValue = asfloat16((uint16_t)(_NvInterlockedAddFp16x2(byteAddress, packedInput) >> 16));\n")
6728
0
SLANG_RAW("            }\n")
6729
0
SLANG_RAW("            return;\n")
6730
0
SLANG_RAW("        default:\n")
6731
0
SLANG_RAW("            {\n")
6732
0
SLANG_RAW("                let buf = __getEquivalentStructuredBuffer<half2>(this);\n")
6733
0
SLANG_RAW("                if ((byteAddress & 2) == 0)\n")
6734
0
SLANG_RAW("                {\n")
6735
0
SLANG_RAW("                    originalValue = __atomic_add(buf[byteAddress/4], half2(value, half(0.0))).x;\n")
6736
0
SLANG_RAW("                }\n")
6737
0
SLANG_RAW("                else\n")
6738
0
SLANG_RAW("                {\n")
6739
0
SLANG_RAW("                    originalValue = __atomic_add(buf[byteAddress/4], half2(half(0.0), value)).y;\n")
6740
0
SLANG_RAW("                }\n")
6741
0
SLANG_RAW("                return;\n")
6742
0
SLANG_RAW("            }\n")
6743
0
SLANG_RAW("        }\n")
6744
0
SLANG_RAW("    }\n")
6745
0
SLANG_RAW("\n")
6746
0
SLANG_RAW("    // Without returning original value\n")
6747
0
SLANG_RAW("\n")
6748
0
SLANG_RAW("    [__requiresNVAPI]\n")
6749
0
SLANG_RAW("    [ForceInline]\n")
6750
0
SLANG_RAW("    __cuda_sm_version(2.0)\n")
6751
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_nvapi_cuda_metal_float1)]\n")
6752
0
SLANG_RAW("    void InterlockedAddF32(uint byteAddress, float valueToAdd)\n")
6753
0
SLANG_RAW("    {\n")
6754
0
SLANG_RAW("        __target_switch\n")
6755
0
SLANG_RAW("        {\n")
6756
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"(NvInterlockedAddFp32($0, $1, $2))\";\n")
6757
0
SLANG_RAW("        default:\n")
6758
0
SLANG_RAW("            {\n")
6759
0
SLANG_RAW("                let buf = __getEquivalentStructuredBuffer<float>(this);\n")
6760
0
SLANG_RAW("                __atomic_add(buf[byteAddress / 4], valueToAdd);\n")
6761
0
SLANG_RAW("                return;\n")
6762
0
SLANG_RAW("            }\n")
6763
0
SLANG_RAW("        }\n")
6764
0
SLANG_RAW("    }\n")
6765
0
SLANG_RAW("\n")
6766
0
SLANG_RAW("    // Int64 Add\n")
6767
0
SLANG_RAW("\n")
6768
0
SLANG_RAW("    /// Perform a 64-bit integer atomic add operation at `byteAddress`.\n")
6769
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic add operation.\n")
6770
0
SLANG_RAW("    /// @param valueToAdd The value to add to the value at `byteAddress`.\n")
6771
0
SLANG_RAW("    /// @param originalValue The original value at `byteAddress` before the add operation.\n")
6772
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicAdd`. For HLSL, this function\n")
6773
0
SLANG_RAW("    /// translates to `InterlockedAdd64` and requires shader model 6.6.\n")
6774
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicAdd`.\n")
6775
0
SLANG_RAW("    [ForceInline]\n")
6776
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6777
0
SLANG_RAW("    void InterlockedAddI64(uint byteAddress, int64_t valueToAdd, out int64_t originalValue)\n")
6778
0
SLANG_RAW("    {\n")
6779
0
SLANG_RAW("        InterlockedAdd64(byteAddress, valueToAdd, originalValue);\n")
6780
0
SLANG_RAW("    }\n")
6781
0
SLANG_RAW("\n")
6782
0
SLANG_RAW("    // Without returning original value\n")
6783
0
SLANG_RAW("    [ForceInline]\n")
6784
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6785
0
SLANG_RAW("    void InterlockedAddI64(uint byteAddress, int64_t valueToAdd)\n")
6786
0
SLANG_RAW("    {\n")
6787
0
SLANG_RAW("        InterlockedAdd64(byteAddress, valueToAdd);\n")
6788
0
SLANG_RAW("    }\n")
6789
0
SLANG_RAW("\n")
6790
0
SLANG_RAW("    // Cas uint64_t\n")
6791
0
SLANG_RAW("\n")
6792
0
SLANG_RAW("    /// Perform a 64-bit integer atomic compare-and-exchange operation at `byteAddress`.\n")
6793
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic compare-and-exchange operation.\n")
6794
0
SLANG_RAW("    /// @param compareValue The value to compare to the value at `byteAddress`.\n")
6795
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the comparison is successful.\n")
6796
0
SLANG_RAW("    /// @param outOriginalValue The original value at `byteAddress` before the add operation.\n")
6797
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
6798
0
SLANG_RAW("    /// translates to `InterlockedCompareExchange64` and requires shader model 6.6.\n")
6799
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
6800
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6801
0
SLANG_RAW("    void InterlockedCompareExchangeU64(uint byteAddress, uint64_t compareValue, uint64_t value, out uint64_t outOriginalValue)\n")
6802
0
SLANG_RAW("    {\n")
6803
0
SLANG_RAW("        __target_switch\n")
6804
0
SLANG_RAW("        {\n")
6805
0
SLANG_RAW("        case cuda: __intrinsic_asm \"(*$4 = atomicCAS($0._getPtrAt<uint64_t>($1), $2, $3))\";\n")
6806
0
SLANG_RAW("        case hlsl:\n")
6807
0
SLANG_RAW("            __intrinsic_asm \".InterlockedCompareExchange64\";\n")
6808
0
SLANG_RAW("        default:\n")
6809
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<uint64_t>(this);\n")
6810
0
SLANG_RAW("            outOriginalValue = __atomic_compare_exchange(buf[byteAddress / 8], compareValue, value);\n")
6811
0
SLANG_RAW("        }\n")
6812
0
SLANG_RAW("    }\n")
6813
0
SLANG_RAW("\n")
6814
0
SLANG_RAW("    // SM6.6 6 64bit atomics.\n")
6815
0
SLANG_RAW("\n")
6816
0
SLANG_RAW("    // InterlockedMax64, InterlockedMin64, InterlockedAdd64, InterlockedAnd64, InterlockedOr64, InterlockedXor64, InterlockedExchange64\n")
6817
6818
0
    for (auto op : bufferAtomicOps) {
6819
0
SLANG_RAW("#line 5686 \"hlsl.meta.slang\"")
6820
0
SLANG_RAW("\n")
6821
0
SLANG_RAW("\n")
6822
0
SLANG_RAW("    /// Perform a 64-bit unsigned integer atomic ")
6823
0
SLANG_SPLICE(op.internalName
6824
0
)
6825
0
SLANG_RAW(" operation at `byteAddress`.\n")
6826
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic ")
6827
0
SLANG_SPLICE(op.internalName
6828
0
)
6829
0
SLANG_RAW(" operation.\n")
6830
0
SLANG_RAW("    /// @param value The operand for the ")
6831
0
SLANG_SPLICE(op.internalName
6832
0
)
6833
0
SLANG_RAW(" operation.\n")
6834
0
SLANG_RAW("    [ForceInline]\n")
6835
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6836
0
SLANG_RAW("    uint64_t Interlocked")
6837
0
SLANG_SPLICE(op.name
6838
0
)
6839
0
SLANG_RAW("U64(uint byteAddress, uint64_t value)\n")
6840
0
SLANG_RAW("    {\n")
6841
0
SLANG_RAW("        uint64_t originalValue;\n")
6842
0
SLANG_RAW("        Interlocked")
6843
0
SLANG_SPLICE(op.name
6844
0
)
6845
0
SLANG_RAW("64(byteAddress, value, originalValue);\n")
6846
0
SLANG_RAW("        return originalValue;\n")
6847
0
SLANG_RAW("    }\n")
6848
0
SLANG_RAW("\n")
6849
0
SLANG_RAW("    [ForceInline]\n")
6850
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6851
0
SLANG_RAW("    void Interlocked")
6852
0
SLANG_SPLICE(op.name
6853
0
)
6854
0
SLANG_RAW("64(uint byteAddress, int64_t value)\n")
6855
0
SLANG_RAW("    {\n")
6856
0
SLANG_RAW("        int64_t oldValue;\n")
6857
0
SLANG_RAW("        Interlocked")
6858
0
SLANG_SPLICE(op.name
6859
0
)
6860
0
SLANG_RAW("64(byteAddress, value, oldValue);\n")
6861
0
SLANG_RAW("    }\n")
6862
0
SLANG_RAW("\n")
6863
0
SLANG_RAW("    /// Perform a 64-bit integer atomic ")
6864
0
SLANG_SPLICE(op.internalName
6865
0
)
6866
0
SLANG_RAW(" operation at `byteAddress`.\n")
6867
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic ")
6868
0
SLANG_SPLICE(op.internalName
6869
0
)
6870
0
SLANG_RAW(" operation.\n")
6871
0
SLANG_RAW("    /// @param value The operand for the ")
6872
0
SLANG_SPLICE(op.internalName
6873
0
)
6874
0
SLANG_RAW(" operation.\n")
6875
0
SLANG_RAW("    /// @param outOriginalValue The original value at `byteAddress` before the ")
6876
0
SLANG_SPLICE(op.internalName
6877
0
)
6878
0
SLANG_RAW(" operation.\n")
6879
0
SLANG_RAW("    [ForceInline]\n")
6880
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6881
0
SLANG_RAW("    void Interlocked")
6882
0
SLANG_SPLICE(op.name
6883
0
)
6884
0
SLANG_RAW("64<T:__BuiltinInt64Type>(uint byteAddress, T value, out T outOriginalValue)\n")
6885
0
SLANG_RAW("    {\n")
6886
0
SLANG_RAW("        __target_switch\n")
6887
0
SLANG_RAW("        {\n")
6888
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Interlocked")
6889
0
SLANG_SPLICE(op.name
6890
0
)
6891
0
SLANG_RAW("64\";\n")
6892
0
SLANG_RAW("        default:\n")
6893
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<T>(this);\n")
6894
0
SLANG_RAW("            outOriginalValue = __atomic_")
6895
0
SLANG_SPLICE(op.internalName
6896
0
)
6897
0
SLANG_RAW("(buf[byteAddress / 8], value);\n")
6898
0
SLANG_RAW("            return;\n")
6899
0
SLANG_RAW("        }\n")
6900
0
SLANG_RAW("    }\n")
6901
6902
0
} // for (each bufferOps)
6903
0
SLANG_RAW("#line 5727 \"hlsl.meta.slang\"")
6904
0
SLANG_RAW("\n")
6905
0
SLANG_RAW("\n")
6906
0
SLANG_RAW("    /// Perform a 64-bit integer atomic compare-and-exchange operation at `byteAddress`.\n")
6907
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic compare-and-exchange operation.\n")
6908
0
SLANG_RAW("    /// @param compareValue The value to compare to the value at `byteAddress`.\n")
6909
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the comparison is successful.\n")
6910
0
SLANG_RAW("    /// @param outOriginalValue The original value at `byteAddress` before the add operation.\n")
6911
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
6912
0
SLANG_RAW("    /// translates to `InterlockedCompareExchange64` and requires shader model 6.6.\n")
6913
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
6914
0
SLANG_RAW("    [ForceInline]\n")
6915
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6916
0
SLANG_RAW("    void InterlockedCompareExchange64<T:__BuiltinInt64Type>(uint byteAddress, T compareValue, T value, out T outOriginalValue)\n")
6917
0
SLANG_RAW("    {\n")
6918
0
SLANG_RAW("        __target_switch\n")
6919
0
SLANG_RAW("        {\n")
6920
0
SLANG_RAW("        case hlsl:\n")
6921
0
SLANG_RAW("            __intrinsic_asm \".InterlockedCompareExchange64\";\n")
6922
0
SLANG_RAW("        default:\n")
6923
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<T>(this);\n")
6924
0
SLANG_RAW("            outOriginalValue = __atomic_compare_exchange(buf[byteAddress / 8], compareValue, value);\n")
6925
0
SLANG_RAW("            return;\n")
6926
0
SLANG_RAW("        }\n")
6927
0
SLANG_RAW("    }\n")
6928
0
SLANG_RAW("\n")
6929
0
SLANG_RAW("    /// Perform a floating-point atomic bitwise compare-and-exchange operation at `byteAddress`.\n")
6930
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic exchange operation.\n")
6931
0
SLANG_RAW("    /// @param compareValue The value to compare to the value at `byteAddress`.\n")
6932
0
SLANG_RAW("    /// @param value The value to store at `byteAddress`.\n")
6933
0
SLANG_RAW("    /// @param [out] outOriginalValue The original value at `byteAddress` before the exchange operation.\n")
6934
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
6935
0
SLANG_RAW("    /// translates to `InterlockedCompareExchangeFloatBitwise` and requires shader model 6.6.\n")
6936
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
6937
0
SLANG_RAW("    [ForceInline]\n")
6938
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6939
0
SLANG_RAW("    void InterlockedCompareExchangeFloatBitwise(uint byteAddress, float compareValue, float value, out float outOriginalValue)\n")
6940
0
SLANG_RAW("    {\n")
6941
0
SLANG_RAW("        __target_switch\n")
6942
0
SLANG_RAW("        {\n")
6943
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedCompareExchangeFloatBitwise\";\n")
6944
0
SLANG_RAW("        default:\n")
6945
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<float>(this);\n")
6946
0
SLANG_RAW("            outOriginalValue = __atomic_compare_exchange(buf[byteAddress / 4], compareValue, value);\n")
6947
0
SLANG_RAW("            return;\n")
6948
0
SLANG_RAW("        }\n")
6949
0
SLANG_RAW("    }\n")
6950
0
SLANG_RAW("\n")
6951
0
SLANG_RAW("    /// Perform a floating-point atomic bitwise exchange operation at `byteAddress`.\n")
6952
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic exchange operation.\n")
6953
0
SLANG_RAW("    /// @param value The value to store at `byteAddress`.\n")
6954
0
SLANG_RAW("    /// @param [out] outOriginalValue The original value at `byteAddress` before the exchange operation.\n")
6955
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicExchange`. For HLSL, this function\n")
6956
0
SLANG_RAW("    /// translates to `InterlockedExchangeFloat` and requires shader model 6.6.\n")
6957
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicExch`.\n")
6958
0
SLANG_RAW("    [ForceInline]\n")
6959
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6960
0
SLANG_RAW("    void InterlockedExchangeFloat(uint byteAddress, float value, out float outOriginalValue)\n")
6961
0
SLANG_RAW("    {\n")
6962
0
SLANG_RAW("        __target_switch\n")
6963
0
SLANG_RAW("        {\n")
6964
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedExchangeFloat\";\n")
6965
0
SLANG_RAW("        default:\n")
6966
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<float>(this);\n")
6967
0
SLANG_RAW("            outOriginalValue = __atomic_exchange(buf[byteAddress / 4], value);\n")
6968
0
SLANG_RAW("            return;\n")
6969
0
SLANG_RAW("        }\n")
6970
0
SLANG_RAW("    }\n")
6971
0
SLANG_RAW("\n")
6972
0
SLANG_RAW("    /// Perform a 64-bit integer atomic compare-and-store operation at `byteAddress`.\n")
6973
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic store operation.\n")
6974
0
SLANG_RAW("    /// @param compareValue The value to compare to the value at `byteAddress`.\n")
6975
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the the value at address is equal to `compareValue`.\n")
6976
0
SLANG_RAW("    /// @param [out] outOriginalValue The original value at `byteAddress` before the store operation.\n")
6977
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
6978
0
SLANG_RAW("    /// translates to `InterlockedCompareStore64` and requires shader model 6.6.\n")
6979
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
6980
0
SLANG_RAW("    [ForceInline]\n")
6981
0
SLANG_RAW("    [ForceInline]\n")
6982
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
6983
0
SLANG_RAW("    void InterlockedCompareStore64<T:__BuiltinInt64Type>(uint byteAddress, T compareValue, T value)\n")
6984
0
SLANG_RAW("    {\n")
6985
0
SLANG_RAW("        __target_switch\n")
6986
0
SLANG_RAW("        {\n")
6987
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedCompareStore64\";\n")
6988
0
SLANG_RAW("        default:\n")
6989
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<T>(this);\n")
6990
0
SLANG_RAW("            __atomic_compare_exchange(buf[byteAddress / 8], compareValue, value);\n")
6991
0
SLANG_RAW("            return;\n")
6992
0
SLANG_RAW("        }\n")
6993
0
SLANG_RAW("    }\n")
6994
0
SLANG_RAW("\n")
6995
0
SLANG_RAW("    /// Perform a floating-point atomic bitwise compare-and-store operation at `byteAddress`.\n")
6996
0
SLANG_RAW("    /// @param byteAddress The address at which to perform the atomic compare-and-exchange  operation.\n")
6997
0
SLANG_RAW("    /// @param compareValue The value to perform bitwise comparison to the value at `byteAddress`.\n")
6998
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the comparison is successful.\n")
6999
0
SLANG_RAW("    /// @param [out] outOriginalValue The original value at `byteAddress` before the compare-and-exchange operation.\n")
7000
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
7001
0
SLANG_RAW("    /// translates to `InterlockedCompareStoreFloatBitwise` and requires shader model 6.6.\n")
7002
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
7003
0
SLANG_RAW("    [ForceInline]\n")
7004
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, atomic_glsl_hlsl_cuda9_int64)]\n")
7005
0
SLANG_RAW("    void InterlockedCompareStoreFloatBitwise(uint byteAddress, float compareValue, float value)\n")
7006
0
SLANG_RAW("    {\n")
7007
0
SLANG_RAW("        __target_switch\n")
7008
0
SLANG_RAW("        {\n")
7009
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedCompareStoreFloatBitwise\";\n")
7010
0
SLANG_RAW("        default:\n")
7011
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<float>(this);\n")
7012
0
SLANG_RAW("            __atomic_compare_exchange(buf[byteAddress / 4], compareValue, value);\n")
7013
0
SLANG_RAW("            return;\n")
7014
0
SLANG_RAW("        }\n")
7015
0
SLANG_RAW("    }\n")
7016
0
SLANG_RAW("\n")
7017
7018
0
    } // endif (type == RWByteAddressBuffer)
7019
0
SLANG_RAW("#line 5842 \"hlsl.meta.slang\"")
7020
0
SLANG_RAW("\n")
7021
0
SLANG_RAW("\n")
7022
0
SLANG_RAW("    // 32-bit atomic operations:\n")
7023
0
SLANG_RAW("    // InterlockedMax, InterlockedMin, InterlockedAdd, InterlockedAnd, InterlockedOr, InterlockedXor, InterlockedExchange\n")
7024
7025
0
    for (auto op : bufferAtomicOps) {
7026
0
SLANG_RAW("#line 5848 \"hlsl.meta.slang\"")
7027
0
SLANG_RAW("\n")
7028
0
SLANG_RAW("\n")
7029
0
SLANG_RAW("    /// Perform an atomic ")
7030
0
SLANG_SPLICE(op.internalName
7031
0
)
7032
0
SLANG_RAW(" operation at the specified byte\n")
7033
0
SLANG_RAW("    /// location of the byte address buffer.\n")
7034
0
SLANG_RAW("    /// @param dest The byte address at which to perform the atomic ")
7035
0
SLANG_SPLICE(op.internalName
7036
0
)
7037
0
SLANG_RAW(" operation.\n")
7038
0
SLANG_RAW("    /// @param value The operand of the atomic operation.\n")
7039
0
SLANG_RAW("    /// @param original_value The original value at `dest` before the ")
7040
0
SLANG_SPLICE(op.internalName
7041
0
)
7042
0
SLANG_RAW(" operation.\n")
7043
0
SLANG_RAW("    [ForceInline]\n")
7044
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
7045
0
SLANG_RAW("    void Interlocked")
7046
0
SLANG_SPLICE(op.name
7047
0
)
7048
0
SLANG_RAW("(\n")
7049
0
SLANG_RAW("        UINT dest,\n")
7050
0
SLANG_RAW("        UINT value,\n")
7051
0
SLANG_RAW("        out UINT original_value)\n")
7052
0
SLANG_RAW("    {\n")
7053
0
SLANG_RAW("        __target_switch\n")
7054
0
SLANG_RAW("        {\n")
7055
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Interlocked")
7056
0
SLANG_SPLICE(op.name
7057
0
)
7058
0
SLANG_RAW("\";\n")
7059
0
SLANG_RAW("        default:\n")
7060
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<uint>(this);\n")
7061
0
SLANG_RAW("            ::Interlocked")
7062
0
SLANG_SPLICE(op.name
7063
0
)
7064
0
SLANG_RAW("(buf[dest / 4], value, original_value);\n")
7065
0
SLANG_RAW("        }\n")
7066
0
SLANG_RAW("    }\n")
7067
0
SLANG_RAW("\n")
7068
0
SLANG_RAW("    [ForceInline]\n")
7069
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
7070
0
SLANG_RAW("    void Interlocked")
7071
0
SLANG_SPLICE(op.name
7072
0
)
7073
0
SLANG_RAW("(\n")
7074
0
SLANG_RAW("        UINT dest,\n")
7075
0
SLANG_RAW("        UINT value)\n")
7076
0
SLANG_RAW("    {\n")
7077
0
SLANG_RAW("        __target_switch\n")
7078
0
SLANG_RAW("        {\n")
7079
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Interlocked")
7080
0
SLANG_SPLICE(op.name
7081
0
)
7082
0
SLANG_RAW("\";\n")
7083
0
SLANG_RAW("        default:\n")
7084
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<uint>(this);\n")
7085
0
SLANG_RAW("            ::Interlocked")
7086
0
SLANG_SPLICE(op.name
7087
0
)
7088
0
SLANG_RAW("(buf[dest / 4], value);\n")
7089
0
SLANG_RAW("        }\n")
7090
0
SLANG_RAW("    }\n")
7091
7092
0
} // for (buffer atomic ops)
7093
0
SLANG_RAW("#line 5887 \"hlsl.meta.slang\"")
7094
0
SLANG_RAW("\n")
7095
0
SLANG_RAW("\n")
7096
0
SLANG_RAW("    /// Perform a 32-bit integer atomic compare-and-exchange operation at\n")
7097
0
SLANG_RAW("    /// the specified byte address within the `RWByteAddressBuffer`.\n")
7098
0
SLANG_RAW("    /// @param dest The address at which to perform the atomic compare-and-exchange operation.\n")
7099
0
SLANG_RAW("    /// @param compare_value The value to perform bitwise comparison to the value at `byteAddress`.\n")
7100
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the comparison is successful.\n")
7101
0
SLANG_RAW("    /// @param original_value The original value at `byteAddress` before the compare-and-exchange operation.\n")
7102
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
7103
0
SLANG_RAW("    /// translates to `InterlockedCompareExchange`.\n")
7104
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
7105
0
SLANG_RAW("    [ForceInline]\n")
7106
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
7107
0
SLANG_RAW("    void InterlockedCompareExchange(\n")
7108
0
SLANG_RAW("        UINT dest,\n")
7109
0
SLANG_RAW("        UINT compare_value,\n")
7110
0
SLANG_RAW("        UINT value,\n")
7111
0
SLANG_RAW("        out UINT original_value)\n")
7112
0
SLANG_RAW("    {\n")
7113
0
SLANG_RAW("        __target_switch\n")
7114
0
SLANG_RAW("        {\n")
7115
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedCompareExchange\";\n")
7116
0
SLANG_RAW("        default:\n")
7117
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<uint>(this);\n")
7118
0
SLANG_RAW("            ::InterlockedCompareExchange(buf[dest / 4], compare_value, value, original_value);\n")
7119
0
SLANG_RAW("        }\n")
7120
0
SLANG_RAW("    }\n")
7121
0
SLANG_RAW("\n")
7122
0
SLANG_RAW("    /// Perform a 32-bit integer atomic compare-and-store operation at\n")
7123
0
SLANG_RAW("    /// the specified byte address within the `RWByteAddressBuffer`.\n")
7124
0
SLANG_RAW("    /// @param dest The address at which to perform the atomic add operation.\n")
7125
0
SLANG_RAW("    /// @param compare_value The value to perform comparison to the value at `byteAddress`.\n")
7126
0
SLANG_RAW("    /// @param value The value to store at `byteAddress` if the comparison is successful.\n")
7127
0
SLANG_RAW("    /// @remarks For SPIR-V, this function maps to `OpAtomicCompareExchange`. For HLSL, this function\n")
7128
0
SLANG_RAW("    /// translates to `InterlockedCompareStore`.\n")
7129
0
SLANG_RAW("    /// For CUDA, this function maps to `atomicCAS`.\n")
7130
0
SLANG_RAW("    [ForceInline]\n")
7131
0
SLANG_RAW("    [require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
7132
0
SLANG_RAW("    void InterlockedCompareStore(\n")
7133
0
SLANG_RAW("        UINT dest,\n")
7134
0
SLANG_RAW("        UINT compare_value,\n")
7135
0
SLANG_RAW("        UINT value)\n")
7136
0
SLANG_RAW("    {\n")
7137
0
SLANG_RAW("        __target_switch\n")
7138
0
SLANG_RAW("        {\n")
7139
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".InterlockedCompareStore\";\n")
7140
0
SLANG_RAW("        default:\n")
7141
0
SLANG_RAW("            let buf = __getEquivalentStructuredBuffer<uint>(this);\n")
7142
0
SLANG_RAW("            ::InterlockedCompareStore(buf[dest / 4], compare_value, value);\n")
7143
0
SLANG_RAW("        }\n")
7144
0
SLANG_RAW("    }\n")
7145
0
SLANG_RAW("\n")
7146
0
SLANG_RAW("    /// Set one value to the buffer at the specified location.\n")
7147
0
SLANG_RAW("    ///@param T The type of the value to load from the buffer.\n")
7148
0
SLANG_RAW("    ///@param value The input value.\n")
7149
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 4.\n")
7150
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
7151
0
SLANG_RAW("    [ForceInline]\n")
7152
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7153
0
SLANG_RAW("    void Store(uint address, uint value)\n")
7154
0
SLANG_RAW("    {\n")
7155
0
SLANG_RAW("        __target_switch\n")
7156
0
SLANG_RAW("        {\n")
7157
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store\";\n")
7158
0
SLANG_RAW("        default:\n")
7159
0
SLANG_RAW("            __byteAddressBufferStore(this, address, 0, value);\n")
7160
0
SLANG_RAW("        }\n")
7161
0
SLANG_RAW("    }\n")
7162
0
SLANG_RAW("\n")
7163
0
SLANG_RAW("\n")
7164
0
SLANG_RAW("    /// Set two values to the buffer at the specified location.\n")
7165
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 4.\n")
7166
0
SLANG_RAW("    ///@param value Two input values.\n")
7167
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
7168
0
SLANG_RAW("    [ForceInline]\n")
7169
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7170
0
SLANG_RAW("    void Store2(uint address, uint2 value)\n")
7171
0
SLANG_RAW("    {\n")
7172
0
SLANG_RAW("        __target_switch\n")
7173
0
SLANG_RAW("        {\n")
7174
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store2\";\n")
7175
0
SLANG_RAW("        default:\n")
7176
0
SLANG_RAW("            __byteAddressBufferStore(this, address, 0, value);\n")
7177
0
SLANG_RAW("        }\n")
7178
0
SLANG_RAW("    }\n")
7179
0
SLANG_RAW("\n")
7180
0
SLANG_RAW("\n")
7181
0
SLANG_RAW("    [ForceInline]\n")
7182
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7183
0
SLANG_RAW("    void Store2(uint address, uint2 value, uint alignment)\n")
7184
0
SLANG_RAW("    {\n")
7185
0
SLANG_RAW("        __target_switch\n")
7186
0
SLANG_RAW("        {\n")
7187
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store2\";\n")
7188
0
SLANG_RAW("        default:\n")
7189
0
SLANG_RAW("            __byteAddressBufferStore(this, address, alignment, value);\n")
7190
0
SLANG_RAW("        }\n")
7191
0
SLANG_RAW("    }\n")
7192
0
SLANG_RAW("\n")
7193
0
SLANG_RAW("    /// Set two values to the buffer at the specified location, the address will be aligned\n")
7194
0
SLANG_RAW("    /// to the alignment of  `uint2`, which is 8.\n")
7195
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 8.\n")
7196
0
SLANG_RAW("    ///@param value Two input values.\n")
7197
0
SLANG_RAW("    [ForceInline]\n")
7198
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7199
0
SLANG_RAW("    void Store2Aligned(uint address, uint2 value)\n")
7200
0
SLANG_RAW("    {\n")
7201
0
SLANG_RAW("        __target_switch\n")
7202
0
SLANG_RAW("        {\n")
7203
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store2\";\n")
7204
0
SLANG_RAW("        default:\n")
7205
0
SLANG_RAW("            __byteAddressBufferStore(this, address, __naturalStrideOf<uint2>(), value);\n")
7206
0
SLANG_RAW("        }\n")
7207
0
SLANG_RAW("    }\n")
7208
0
SLANG_RAW("\n")
7209
0
SLANG_RAW("    /// Set three values to the buffer at the specified location.\n")
7210
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 4.\n")
7211
0
SLANG_RAW("    ///@param value Three input values.\n")
7212
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
7213
0
SLANG_RAW("    [ForceInline]\n")
7214
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7215
0
SLANG_RAW("    void Store3(uint address, uint3 value)\n")
7216
0
SLANG_RAW("    {\n")
7217
0
SLANG_RAW("        __target_switch\n")
7218
0
SLANG_RAW("        {\n")
7219
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store3\";\n")
7220
0
SLANG_RAW("        default:\n")
7221
0
SLANG_RAW("            __byteAddressBufferStore(this, address, 0, value);\n")
7222
0
SLANG_RAW("        }\n")
7223
0
SLANG_RAW("    }\n")
7224
0
SLANG_RAW("\n")
7225
0
SLANG_RAW("    [ForceInline]\n")
7226
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7227
0
SLANG_RAW("    void Store3(uint address, uint3 value, uint alignment)\n")
7228
0
SLANG_RAW("    {\n")
7229
0
SLANG_RAW("        __target_switch\n")
7230
0
SLANG_RAW("        {\n")
7231
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store3\";\n")
7232
0
SLANG_RAW("        default:\n")
7233
0
SLANG_RAW("            __byteAddressBufferStore(this, address, alignment, value);\n")
7234
0
SLANG_RAW("        }\n")
7235
0
SLANG_RAW("    }\n")
7236
0
SLANG_RAW("\n")
7237
0
SLANG_RAW("    /// Set three values to the buffer at the specified location, the address will be aligned\n")
7238
0
SLANG_RAW("    /// to the alignment of `uint3`, which is 12.\n")
7239
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 12.\n")
7240
0
SLANG_RAW("    ///@param value Three input values.\n")
7241
0
SLANG_RAW("    [ForceInline]\n")
7242
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7243
0
SLANG_RAW("    void Store3Aligned(uint address, uint3 value)\n")
7244
0
SLANG_RAW("    {\n")
7245
0
SLANG_RAW("        __target_switch\n")
7246
0
SLANG_RAW("        {\n")
7247
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store3\";\n")
7248
0
SLANG_RAW("        default:\n")
7249
0
SLANG_RAW("            __byteAddressBufferStore(this, address, __naturalStrideOf<uint3>(), value);\n")
7250
0
SLANG_RAW("        }\n")
7251
0
SLANG_RAW("    }\n")
7252
0
SLANG_RAW("\n")
7253
0
SLANG_RAW("    /// Set four values to the buffer at the specified location.\n")
7254
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 4.\n")
7255
0
SLANG_RAW("    ///@param value Four input values.\n")
7256
0
SLANG_RAW("    ///@param alignment Specifies the alignment of the location, which must be a multiple of 4.\n")
7257
0
SLANG_RAW("    [ForceInline]\n")
7258
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7259
0
SLANG_RAW("    void Store4(uint address, uint4 value)\n")
7260
0
SLANG_RAW("    {\n")
7261
0
SLANG_RAW("        __target_switch\n")
7262
0
SLANG_RAW("        {\n")
7263
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store4\";\n")
7264
0
SLANG_RAW("        default:\n")
7265
0
SLANG_RAW("            __byteAddressBufferStore(this, address, 0, value);\n")
7266
0
SLANG_RAW("        }\n")
7267
0
SLANG_RAW("    }\n")
7268
0
SLANG_RAW("\n")
7269
0
SLANG_RAW("\n")
7270
0
SLANG_RAW("    [ForceInline]\n")
7271
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7272
0
SLANG_RAW("    void Store4(uint address, uint4 value, uint alignment)\n")
7273
0
SLANG_RAW("    {\n")
7274
0
SLANG_RAW("        __target_switch\n")
7275
0
SLANG_RAW("        {\n")
7276
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store4\";\n")
7277
0
SLANG_RAW("        default:\n")
7278
0
SLANG_RAW("            __byteAddressBufferStore(this, address, alignment, value);\n")
7279
0
SLANG_RAW("        }\n")
7280
0
SLANG_RAW("    }\n")
7281
0
SLANG_RAW("\n")
7282
0
SLANG_RAW("    /// Set four values to the buffer at the specified location, the address will be aligned\n")
7283
0
SLANG_RAW("    /// to the alignment of `uint4`, which is 16.\n")
7284
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of 16.\n")
7285
0
SLANG_RAW("    ///@param value Four input values.\n")
7286
0
SLANG_RAW("    [ForceInline]\n")
7287
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7288
0
SLANG_RAW("    void Store4Aligned(uint address, uint4 value)\n")
7289
0
SLANG_RAW("    {\n")
7290
0
SLANG_RAW("        __target_switch\n")
7291
0
SLANG_RAW("        {\n")
7292
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Store4\";\n")
7293
0
SLANG_RAW("        default:\n")
7294
0
SLANG_RAW("            __byteAddressBufferStore(this, address, __naturalStrideOf<uint4>(), value);\n")
7295
0
SLANG_RAW("        }\n")
7296
0
SLANG_RAW("    }\n")
7297
0
SLANG_RAW("\n")
7298
0
SLANG_RAW("    [ForceInline]\n")
7299
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7300
0
SLANG_RAW("    void Store<T>(uint address, T value)\n")
7301
0
SLANG_RAW("    {\n")
7302
0
SLANG_RAW("        __byteAddressBufferStore(this, address, 0, value);\n")
7303
0
SLANG_RAW("    }\n")
7304
0
SLANG_RAW("\n")
7305
0
SLANG_RAW("    [ForceInline]\n")
7306
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7307
0
SLANG_RAW("    void Store<T>(uint address, T value, uint alignment)\n")
7308
0
SLANG_RAW("    {\n")
7309
0
SLANG_RAW("        __byteAddressBufferStore(this, address, alignment, value);\n")
7310
0
SLANG_RAW("    }\n")
7311
0
SLANG_RAW("\n")
7312
0
SLANG_RAW("    /// Set four values to the buffer at the specified location, the address will be aligned\n")
7313
0
SLANG_RAW("    /// to the alignment of `T`.\n")
7314
0
SLANG_RAW("    ///@param T The type of the input value.\n")
7315
0
SLANG_RAW("    ///@param address The input address in bytes, which must be a multiple of size of `T`.\n")
7316
0
SLANG_RAW("    ///@param value The input value.\n")
7317
0
SLANG_RAW("    [ForceInline]\n")
7318
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7319
0
SLANG_RAW("    void StoreAligned<T>(uint address, T value)\n")
7320
0
SLANG_RAW("    {\n")
7321
0
SLANG_RAW("        __byteAddressBufferStore(this, address, __naturalStrideOf<T>(), value);\n")
7322
0
SLANG_RAW("    }\n")
7323
0
SLANG_RAW("};\n")
7324
0
SLANG_RAW("\n")
7325
7326
0
}
7327
0
SLANG_RAW("#line 6120 \"hlsl.meta.slang\"")
7328
0
SLANG_RAW("\n")
7329
0
SLANG_RAW("\n")
7330
7331
0
static const struct {
7332
0
    IROp op;
7333
0
    char const* name;
7334
0
} kMutableStructuredBufferCases[] =
7335
0
{
7336
0
    { kIROp_HLSLRWStructuredBufferType,                "RWStructuredBuffer" },
7337
0
    { kIROp_HLSLRasterizerOrderedStructuredBufferType, "RasterizerOrderedStructuredBuffer" },
7338
0
};
7339
0
for(auto item : kMutableStructuredBufferCases) {
7340
0
SLANG_RAW("#line 6132 \"hlsl.meta.slang\"")
7341
0
SLANG_RAW("\n")
7342
0
SLANG_RAW("\n")
7343
0
SLANG_RAW("__generic<T, L:IBufferDataLayout=DefaultDataLayout>\n")
7344
0
SLANG_RAW("__magic_type(HLSL")
7345
0
SLANG_SPLICE(item.name
7346
0
)
7347
0
SLANG_RAW("Type)\n")
7348
0
SLANG_RAW("__intrinsic_type(")
7349
0
SLANG_SPLICE(item.op
7350
0
)
7351
0
SLANG_RAW(")\n")
7352
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, structuredbuffer_rw)]\n")
7353
0
SLANG_RAW("/**\n")
7354
0
SLANG_RAW("Represents an opaque handle to a mutable structured buffer allocated in global memory.\n")
7355
0
SLANG_RAW("A structured buffer can be viewed as an array of the specified element type.\n")
7356
0
SLANG_RAW(" @param T The element type of the buffer.\n")
7357
0
SLANG_RAW(" @param L The memory layout of the buffer.\n")
7358
0
SLANG_RAW(" @remarks\n")
7359
0
SLANG_RAW("The `L` generic parameter is used to specify the memory layout of the buffer when\n")
7360
0
SLANG_RAW("generating SPIRV.\n")
7361
0
SLANG_RAW("`L` must be one of `DefaultDataLayout`, `Std140DataLayout`, `Std430DataLayout` or `ScalarDataLayout`.\n")
7362
0
SLANG_RAW("The default value is `DefaultDataLayout`.\n")
7363
0
SLANG_RAW("When generating code for other targets, this parameter is ignored and has no effect on the generated code.\n")
7364
0
SLANG_RAW(" @see `StructuredBuffer`, `AppendStructuredBuffer`, `ConsumeStructuredBuffer`\n")
7365
0
SLANG_RAW(" @category buffer_types\n")
7366
0
SLANG_RAW("**/\n")
7367
0
SLANG_RAW("struct ")
7368
0
SLANG_SPLICE(item.name
7369
0
)
7370
0
SLANG_RAW("\n")
7371
0
SLANG_RAW("{\n")
7372
0
SLANG_RAW("    /// Decrements the object's hidden counter.\n")
7373
0
SLANG_RAW("    /// @return The post-decremented counter value.\n")
7374
0
SLANG_RAW("    /// @remarks\n")
7375
0
SLANG_RAW("    /// This function is not implemented when targeting non-HLSL.\n")
7376
0
SLANG_RAW("    uint DecrementCounter();\n")
7377
0
SLANG_RAW("\n")
7378
0
SLANG_RAW("    /// Get the dimensions of the buffer.\n")
7379
0
SLANG_RAW("    /// @param numStructs The number of structures in the buffer.\n")
7380
0
SLANG_RAW("    /// @param stride The stride, in bytes, of each structure element.\n")
7381
0
SLANG_RAW("    [__readNone]\n")
7382
0
SLANG_RAW("    [ForceInline]\n")
7383
0
SLANG_RAW("    [require(cpp_cuda_glsl_hlsl_spirv_wgsl, structuredbuffer_rw)]\n")
7384
0
SLANG_RAW("    void GetDimensions(\n")
7385
0
SLANG_RAW("        out uint numStructs,\n")
7386
0
SLANG_RAW("        out uint stride)\n")
7387
0
SLANG_RAW("    {\n")
7388
0
SLANG_RAW("        __target_switch\n")
7389
0
SLANG_RAW("        {\n")
7390
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetDimensions\";\n")
7391
0
SLANG_RAW("        default:\n")
7392
0
SLANG_RAW("            let rs = __structuredBufferGetDimensions(this);\n")
7393
0
SLANG_RAW("            numStructs = rs.x;\n")
7394
0
SLANG_RAW("            stride = rs.y;\n")
7395
0
SLANG_RAW("        }\n")
7396
0
SLANG_RAW("    }\n")
7397
0
SLANG_RAW("\n")
7398
0
SLANG_RAW("    /// Increment the object's hidden counter.\n")
7399
0
SLANG_RAW("    /// @return The pre-incremented counter value.\n")
7400
0
SLANG_RAW("    /// @remarks\n")
7401
0
SLANG_RAW("    /// This function is not implemented when targeting non-HLSL.\n")
7402
0
SLANG_RAW("    uint IncrementCounter();\n")
7403
0
SLANG_RAW("\n")
7404
0
SLANG_RAW("    /// Load a element from the buffer at the specified location.\n")
7405
0
SLANG_RAW("    /// @param TIndex Type of the index.\n")
7406
0
SLANG_RAW("    /// @param location The index of buffer.\n")
7407
0
SLANG_RAW("    /// @param[out] status The status of the operation.\n")
7408
0
SLANG_RAW("    /// @return The element at the specified index.\n")
7409
0
SLANG_RAW("    ///\n")
7410
0
SLANG_RAW("    /// @remarks\n")
7411
0
SLANG_RAW("    /// You can't access the output parameter `status` directly; instead,\n")
7412
0
SLANG_RAW("    /// pass the status to the `CheckAccessFullyMapped` intrinsic function.\n")
7413
0
SLANG_RAW("    /// `CheckAccessFullyMapped` returns TRUE if all values from the corresponding Sample,\n")
7414
0
SLANG_RAW("    /// Gather, or Load operation accessed mapped tiles in a tiled resource.\n")
7415
0
SLANG_RAW("    /// If any values were taken from an unmapped tile, `CheckAccessFullyMapped` returns FALSE.\n")
7416
0
SLANG_RAW("    /// When targeting non-HLSL, the status is always 0.\n")
7417
0
SLANG_RAW("    [__NoSideEffect]\n")
7418
0
SLANG_RAW("    __intrinsic_op(")
7419
0
SLANG_SPLICE(kIROp_RWStructuredBufferLoad
7420
0
)
7421
0
SLANG_RAW(")\n")
7422
0
SLANG_RAW("    T Load<TIndex : __BuiltinIntegerType>(TIndex location);\n")
7423
0
SLANG_RAW("\n")
7424
0
SLANG_RAW("    [__NoSideEffect]\n")
7425
0
SLANG_RAW("    __intrinsic_op(")
7426
0
SLANG_SPLICE(kIROp_RWStructuredBufferLoadStatus
7427
0
)
7428
0
SLANG_RAW(")\n")
7429
0
SLANG_RAW("    T Load<TIndex : __BuiltinIntegerType>(TIndex location, out uint status);\n")
7430
0
SLANG_RAW("\n")
7431
0
SLANG_RAW("    /// Load a element from the buffer at the specified location.\n")
7432
0
SLANG_RAW("    /// @param TIndex Type of the index.\n")
7433
0
SLANG_RAW("    /// @param index The index of buffer.\n")
7434
0
SLANG_RAW("    /// @return The element at the specified index.\n")
7435
0
SLANG_RAW("    __generic<TIndex : __BuiltinIntegerType>\n")
7436
0
SLANG_RAW("    __subscript(TIndex index) -> T\n")
7437
0
SLANG_RAW("    {\n")
7438
0
SLANG_RAW("        // If a 'Buffer[index]' is referred to by a '__ref', call 'kIROp_RWStructuredBufferGetElementPtr(index)'.\n")
7439
0
SLANG_RAW("        //\n")
7440
0
SLANG_RAW("        // This allows call's to stay aware that the input is from a 'Buffer'.\n")
7441
0
SLANG_RAW("        [__NoSideEffect]\n")
7442
0
SLANG_RAW("        [nonmutating]\n")
7443
0
SLANG_RAW("        __intrinsic_op(")
7444
0
SLANG_SPLICE(kIROp_RWStructuredBufferGetElementPtr
7445
0
)
7446
0
SLANG_RAW(")\n")
7447
0
SLANG_RAW("        ref;\n")
7448
0
SLANG_RAW("    }\n")
7449
0
SLANG_RAW("};\n")
7450
0
SLANG_RAW("\n")
7451
7452
0
}
7453
0
SLANG_RAW("#line 6226 \"hlsl.meta.slang\"")
7454
0
SLANG_RAW("\n")
7455
0
SLANG_RAW("\n")
7456
0
SLANG_RAW("/// @category stage_io\n")
7457
0
SLANG_RAW("__generic<T>\n")
7458
0
SLANG_RAW("[require(glsl_hlsl_spirv, geometry)]\n")
7459
0
SLANG_RAW("__magic_type(HLSLPointStreamType)\n")
7460
0
SLANG_RAW("__intrinsic_type(")
7461
0
SLANG_SPLICE(kIROp_HLSLPointStreamType
7462
0
)
7463
0
SLANG_RAW(")\n")
7464
0
SLANG_RAW("struct PointStream\n")
7465
0
SLANG_RAW("{\n")
7466
0
SLANG_RAW("    [KnownBuiltin(")
7467
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamAppend
7468
0
)
7469
0
SLANG_RAW(")]\n")
7470
0
SLANG_RAW("    void Append(T value)\n")
7471
0
SLANG_RAW("    {\n")
7472
0
SLANG_RAW("        __target_switch\n")
7473
0
SLANG_RAW("        {\n")
7474
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EmitVertex()\";\n")
7475
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Append\";\n")
7476
0
SLANG_RAW("        case spirv: spirv_asm { OpEmitVertex; };\n")
7477
0
SLANG_RAW("        }\n")
7478
0
SLANG_RAW("    }\n")
7479
0
SLANG_RAW("\n")
7480
0
SLANG_RAW("    [KnownBuiltin(")
7481
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamRestart
7482
0
)
7483
0
SLANG_RAW(")]\n")
7484
0
SLANG_RAW("    void RestartStrip()\n")
7485
0
SLANG_RAW("    {\n")
7486
0
SLANG_RAW("        __target_switch\n")
7487
0
SLANG_RAW("        {\n")
7488
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EndPrimitive()\";\n")
7489
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".RestartStrip\";\n")
7490
0
SLANG_RAW("        case spirv: spirv_asm { OpEndPrimitive; };\n")
7491
0
SLANG_RAW("        }\n")
7492
0
SLANG_RAW("    }\n")
7493
0
SLANG_RAW("};\n")
7494
0
SLANG_RAW("\n")
7495
0
SLANG_RAW("/// @category stage_io\n")
7496
0
SLANG_RAW("__generic<T>\n")
7497
0
SLANG_RAW("[require(glsl_hlsl_spirv, geometry)]\n")
7498
0
SLANG_RAW("__magic_type(HLSLLineStreamType)\n")
7499
0
SLANG_RAW("__intrinsic_type(")
7500
0
SLANG_SPLICE(kIROp_HLSLLineStreamType
7501
0
)
7502
0
SLANG_RAW(")\n")
7503
0
SLANG_RAW("struct LineStream\n")
7504
0
SLANG_RAW("{\n")
7505
0
SLANG_RAW("    [KnownBuiltin(")
7506
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamAppend
7507
0
)
7508
0
SLANG_RAW(")]\n")
7509
0
SLANG_RAW("    void Append(T value)\n")
7510
0
SLANG_RAW("    {\n")
7511
0
SLANG_RAW("        __target_switch\n")
7512
0
SLANG_RAW("        {\n")
7513
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EmitVertex()\";\n")
7514
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Append\";\n")
7515
0
SLANG_RAW("        case spirv: spirv_asm { OpEmitVertex; };\n")
7516
0
SLANG_RAW("        }\n")
7517
0
SLANG_RAW("    }\n")
7518
0
SLANG_RAW("\n")
7519
0
SLANG_RAW("    [KnownBuiltin(")
7520
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamRestart
7521
0
)
7522
0
SLANG_RAW(")]\n")
7523
0
SLANG_RAW("    void RestartStrip()\n")
7524
0
SLANG_RAW("    {\n")
7525
0
SLANG_RAW("        __target_switch\n")
7526
0
SLANG_RAW("        {\n")
7527
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EndPrimitive()\";\n")
7528
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".RestartStrip\";\n")
7529
0
SLANG_RAW("        case spirv: spirv_asm { OpEndPrimitive; };\n")
7530
0
SLANG_RAW("        }\n")
7531
0
SLANG_RAW("    }\n")
7532
0
SLANG_RAW("};\n")
7533
0
SLANG_RAW("\n")
7534
0
SLANG_RAW("/// @category stage_io\n")
7535
0
SLANG_RAW("__generic<T>\n")
7536
0
SLANG_RAW("[require(glsl_hlsl_spirv, geometry)]\n")
7537
0
SLANG_RAW("__magic_type(HLSLTriangleStreamType)\n")
7538
0
SLANG_RAW("__intrinsic_type(")
7539
0
SLANG_SPLICE(kIROp_HLSLTriangleStreamType
7540
0
)
7541
0
SLANG_RAW(")\n")
7542
0
SLANG_RAW("struct TriangleStream\n")
7543
0
SLANG_RAW("{\n")
7544
0
SLANG_RAW("    [KnownBuiltin(")
7545
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamAppend
7546
0
)
7547
0
SLANG_RAW(")]\n")
7548
0
SLANG_RAW("    void Append(T value)\n")
7549
0
SLANG_RAW("    {\n")
7550
0
SLANG_RAW("        __target_switch\n")
7551
0
SLANG_RAW("        {\n")
7552
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EmitVertex()\";\n")
7553
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Append\";\n")
7554
0
SLANG_RAW("        case spirv: spirv_asm { OpEmitVertex; };\n")
7555
0
SLANG_RAW("        }\n")
7556
0
SLANG_RAW("    }\n")
7557
0
SLANG_RAW("\n")
7558
0
SLANG_RAW("    [KnownBuiltin(")
7559
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GeometryStreamRestart
7560
0
)
7561
0
SLANG_RAW(")]\n")
7562
0
SLANG_RAW("    void RestartStrip()\n")
7563
0
SLANG_RAW("    {\n")
7564
0
SLANG_RAW("        __target_switch\n")
7565
0
SLANG_RAW("        {\n")
7566
0
SLANG_RAW("        case glsl: __intrinsic_asm \"EndPrimitive()\";\n")
7567
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".RestartStrip\";\n")
7568
0
SLANG_RAW("        case spirv: spirv_asm { OpEndPrimitive; };\n")
7569
0
SLANG_RAW("        }\n")
7570
0
SLANG_RAW("    }\n")
7571
0
SLANG_RAW("};\n")
7572
0
SLANG_RAW("\n")
7573
0
SLANG_RAW("#define VECTOR_MAP_UNARY(TYPE, COUNT, FUNC, VALUE) \\\n")
7574
0
SLANG_RAW("    vector<TYPE,COUNT> result; for(int i = 0; i < COUNT; ++i) { result[i] = FUNC(VALUE[i]); } return result\n")
7575
0
SLANG_RAW("\n")
7576
0
SLANG_RAW("#define MATRIX_MAP_UNARY(TYPE, ROWS, COLS, FUNC, VALUE) \\\n")
7577
0
SLANG_RAW("    matrix<TYPE,ROWS,COLS> result; for(int i = 0; i < ROWS; ++i) { result[i] = FUNC(VALUE[i]); } return result\n")
7578
0
SLANG_RAW("\n")
7579
0
SLANG_RAW("#define VECTOR_MAP_BINARY(TYPE, COUNT, FUNC, LEFT, RIGHT) \\\n")
7580
0
SLANG_RAW("    vector<TYPE,COUNT> result; for(int i = 0; i < COUNT; ++i) { result[i] = FUNC(LEFT[i], RIGHT[i]); } return result\n")
7581
0
SLANG_RAW("\n")
7582
0
SLANG_RAW("#define MATRIX_MAP_BINARY(TYPE, ROWS, COLS, FUNC, LEFT, RIGHT) \\\n")
7583
0
SLANG_RAW("    matrix<TYPE,ROWS,COLS> result; for(int i = 0; i < ROWS; ++i) { result[i] = FUNC(LEFT[i], RIGHT[i]); } return result\n")
7584
0
SLANG_RAW("\n")
7585
0
SLANG_RAW("#define VECTOR_MAP_TRINARY(TYPE, COUNT, FUNC, A, B, C) \\\n")
7586
0
SLANG_RAW("    vector<TYPE,COUNT> result; for(int i = 0; i < COUNT; ++i) { result[i] = FUNC(A[i], B[i], C[i]); } return result\n")
7587
0
SLANG_RAW("\n")
7588
0
SLANG_RAW("#define MATRIX_MAP_TRINARY(TYPE, ROWS, COLS, FUNC, A, B, C) \\\n")
7589
0
SLANG_RAW("    matrix<TYPE,ROWS,COLS> result; for(int i = 0; i < ROWS; ++i) { result[i] = FUNC(A[i], B[i], C[i]); } return result\n")
7590
0
SLANG_RAW("\n")
7591
0
SLANG_RAW("//@public:\n")
7592
0
SLANG_RAW("\n")
7593
0
SLANG_RAW("/// Try to terminate the current draw or dispatch call (HLSL SM 4.0)\n")
7594
0
SLANG_RAW("void abort();\n")
7595
0
SLANG_RAW("\n")
7596
0
SLANG_RAW("/// The abs function returns the absolute value of x.\n")
7597
0
SLANG_RAW("/// @param x The input value.\n")
7598
0
SLANG_RAW("/// @return The absolute value of x.\n")
7599
0
SLANG_RAW("/// @category math\n")
7600
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
7601
0
SLANG_RAW("[__readNone]\n")
7602
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7603
0
SLANG_RAW("T abs(T x)\n")
7604
0
SLANG_RAW("{\n")
7605
0
SLANG_RAW("    __target_switch\n")
7606
0
SLANG_RAW("    {\n")
7607
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7608
0
SLANG_RAW("    case glsl: __intrinsic_asm \"abs\";\n")
7609
0
SLANG_RAW("    case metal: __intrinsic_asm \"abs\";\n")
7610
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_abs($0)\";\n")
7611
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_abs($0)\";\n")
7612
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7613
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 SAbs $x\n")
7614
0
SLANG_RAW("    };\n")
7615
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"abs\";\n")
7616
0
SLANG_RAW("    //default:\n")
7617
0
SLANG_RAW("    // Note: this simple definition may not be appropriate for floating-point inputs\n")
7618
0
SLANG_RAW("    // return x < 0 ? -x : x;\n")
7619
0
SLANG_RAW("    }\n")
7620
0
SLANG_RAW("}\n")
7621
0
SLANG_RAW("\n")
7622
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
7623
0
SLANG_RAW("[__readNone]\n")
7624
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7625
0
SLANG_RAW("vector<T, N> abs(vector<T, N> x)\n")
7626
0
SLANG_RAW("{\n")
7627
0
SLANG_RAW("    __target_switch\n")
7628
0
SLANG_RAW("    {\n")
7629
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7630
0
SLANG_RAW("    case glsl: __intrinsic_asm \"abs\";\n")
7631
0
SLANG_RAW("    case metal: __intrinsic_asm \"abs\";\n")
7632
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7633
0
SLANG_RAW("        result:$$vector<T,N> = OpExtInst glsl450 SAbs $x;\n")
7634
0
SLANG_RAW("    };\n")
7635
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"abs\";\n")
7636
0
SLANG_RAW("    default:\n")
7637
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, abs, x);\n")
7638
0
SLANG_RAW("    }\n")
7639
0
SLANG_RAW("}\n")
7640
0
SLANG_RAW("\n")
7641
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
7642
0
SLANG_RAW("[__readNone]\n")
7643
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7644
0
SLANG_RAW("matrix<T,N,M> abs(matrix<T,N,M> x)\n")
7645
0
SLANG_RAW("{\n")
7646
0
SLANG_RAW("    __target_switch\n")
7647
0
SLANG_RAW("    {\n")
7648
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7649
0
SLANG_RAW("    default:\n")
7650
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, abs, x);\n")
7651
0
SLANG_RAW("    }\n")
7652
0
SLANG_RAW("}\n")
7653
0
SLANG_RAW("\n")
7654
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
7655
0
SLANG_RAW("[__readNone]\n")
7656
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7657
0
SLANG_RAW("T abs(T x)\n")
7658
0
SLANG_RAW("{\n")
7659
0
SLANG_RAW("    __target_switch\n")
7660
0
SLANG_RAW("    {\n")
7661
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7662
0
SLANG_RAW("    case metal: __intrinsic_asm \"abs\";\n")
7663
0
SLANG_RAW("    case glsl: __intrinsic_asm \"abs\";\n")
7664
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_abs($0)\";\n")
7665
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_abs($0)\";\n")
7666
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7667
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 FAbs $x;\n")
7668
0
SLANG_RAW("    };\n")
7669
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"abs\";\n")
7670
0
SLANG_RAW("    }\n")
7671
0
SLANG_RAW("}\n")
7672
0
SLANG_RAW("\n")
7673
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
7674
0
SLANG_RAW("[__readNone]\n")
7675
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7676
0
SLANG_RAW("vector<T, N> abs(vector<T, N> x)\n")
7677
0
SLANG_RAW("{\n")
7678
0
SLANG_RAW("    __target_switch\n")
7679
0
SLANG_RAW("    {\n")
7680
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7681
0
SLANG_RAW("    case metal: __intrinsic_asm \"abs\";\n")
7682
0
SLANG_RAW("    case glsl: __intrinsic_asm \"abs\";\n")
7683
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7684
0
SLANG_RAW("        result:$$vector<T,N> = OpExtInst glsl450 FAbs $x;\n")
7685
0
SLANG_RAW("    };\n")
7686
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"abs\";\n")
7687
0
SLANG_RAW("    default:\n")
7688
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, abs, x);\n")
7689
0
SLANG_RAW("    }\n")
7690
0
SLANG_RAW("}\n")
7691
0
SLANG_RAW("\n")
7692
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
7693
0
SLANG_RAW("[__readNone]\n")
7694
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7695
0
SLANG_RAW("matrix<T,N,M> abs(matrix<T,N,M> x)\n")
7696
0
SLANG_RAW("{\n")
7697
0
SLANG_RAW("    __target_switch\n")
7698
0
SLANG_RAW("    {\n")
7699
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"abs\";\n")
7700
0
SLANG_RAW("    default:\n")
7701
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, abs, x);\n")
7702
0
SLANG_RAW("    }\n")
7703
0
SLANG_RAW("}\n")
7704
0
SLANG_RAW("\n")
7705
0
SLANG_RAW("/// Float-point absolute value.\n")
7706
0
SLANG_RAW("/// @param x The input value.\n")
7707
0
SLANG_RAW("/// @return The absolute value of `x`.\n")
7708
0
SLANG_RAW("/// @remarks For metal targets, this function is equivalent to the `fabs` metal intrinsic.\n")
7709
0
SLANG_RAW("///          For other targets, this function is equivalent to the `abs` slang function.\n")
7710
0
SLANG_RAW("/// @category math\n")
7711
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
7712
0
SLANG_RAW("[__readNone]\n")
7713
0
SLANG_RAW("[ForceInline]\n")
7714
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7715
0
SLANG_RAW("T fabs(T x)\n")
7716
0
SLANG_RAW("{\n")
7717
0
SLANG_RAW("    __target_switch\n")
7718
0
SLANG_RAW("    {\n")
7719
0
SLANG_RAW("    case metal: __intrinsic_asm \"fabs\";\n")
7720
0
SLANG_RAW("    default:\n")
7721
0
SLANG_RAW("        return abs(x);\n")
7722
0
SLANG_RAW("    }\n")
7723
0
SLANG_RAW("}\n")
7724
0
SLANG_RAW("\n")
7725
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
7726
0
SLANG_RAW("[__readNone]\n")
7727
0
SLANG_RAW("[ForceInline]\n")
7728
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7729
0
SLANG_RAW("vector<T, N> fabs(vector<T, N> x)\n")
7730
0
SLANG_RAW("{\n")
7731
0
SLANG_RAW("    __target_switch\n")
7732
0
SLANG_RAW("    {\n")
7733
0
SLANG_RAW("    case metal: __intrinsic_asm \"fabs\";\n")
7734
0
SLANG_RAW("    default:\n")
7735
0
SLANG_RAW("        return abs(x);\n")
7736
0
SLANG_RAW("    }\n")
7737
0
SLANG_RAW("}\n")
7738
0
SLANG_RAW("\n")
7739
0
SLANG_RAW("\n")
7740
0
SLANG_RAW("/// Arc cosine. Returns the angle whose cosine is the specified number.\n")
7741
0
SLANG_RAW("/// @param x The cosine value.\n")
7742
0
SLANG_RAW("/// @return The angle in radians, in the range of [0, pi].\n")
7743
0
SLANG_RAW("/// @category math\n")
7744
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
7745
0
SLANG_RAW("[__readNone]\n")
7746
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7747
0
SLANG_RAW("T acos(T x)\n")
7748
0
SLANG_RAW("{\n")
7749
0
SLANG_RAW("    __target_switch\n")
7750
0
SLANG_RAW("    {\n")
7751
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_acos($0)\";\n")
7752
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_acos($0)\";\n")
7753
0
SLANG_RAW("    case glsl: __intrinsic_asm \"acos\";\n")
7754
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"acos\";\n")
7755
0
SLANG_RAW("    case metal: __intrinsic_asm \"acos\";\n")
7756
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7757
0
SLANG_RAW("        OpExtInst $$T result glsl450 Acos $x\n")
7758
0
SLANG_RAW("    };\n")
7759
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"acos\";\n")
7760
0
SLANG_RAW("    }\n")
7761
0
SLANG_RAW("}\n")
7762
0
SLANG_RAW("\n")
7763
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
7764
0
SLANG_RAW("[__readNone]\n")
7765
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7766
0
SLANG_RAW("vector<T, N> acos(vector<T, N> x)\n")
7767
0
SLANG_RAW("{\n")
7768
0
SLANG_RAW("    __target_switch\n")
7769
0
SLANG_RAW("    {\n")
7770
0
SLANG_RAW("    case glsl: __intrinsic_asm \"acos\";\n")
7771
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"acos\";\n")
7772
0
SLANG_RAW("    case metal: __intrinsic_asm \"acos\";\n")
7773
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7774
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Acos $x\n")
7775
0
SLANG_RAW("    };\n")
7776
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"acos\";\n")
7777
0
SLANG_RAW("    default:\n")
7778
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, acos, x);\n")
7779
0
SLANG_RAW("    }\n")
7780
0
SLANG_RAW("}\n")
7781
0
SLANG_RAW("\n")
7782
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
7783
0
SLANG_RAW("[__readNone]\n")
7784
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7785
0
SLANG_RAW("matrix<T, N, M> acos(matrix<T, N, M> x)\n")
7786
0
SLANG_RAW("{\n")
7787
0
SLANG_RAW("    __target_switch\n")
7788
0
SLANG_RAW("    {\n")
7789
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"acos\";\n")
7790
0
SLANG_RAW("    default:\n")
7791
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, acos, x);\n")
7792
0
SLANG_RAW("    }\n")
7793
0
SLANG_RAW("}\n")
7794
0
SLANG_RAW("\n")
7795
0
SLANG_RAW("/// Arc hyperbolic cosine. Returns the arc hyperbolic cosine of the specified value.\n")
7796
0
SLANG_RAW("/// @param x The value.\n")
7797
0
SLANG_RAW("/// @return The arc hyperbolic cosine of the specified value.\n")
7798
0
SLANG_RAW("/// @category math\n")
7799
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
7800
0
SLANG_RAW("[__readNone]\n")
7801
0
SLANG_RAW("[ForceInline]\n")
7802
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7803
0
SLANG_RAW("T acosh(T x)\n")
7804
0
SLANG_RAW("{\n")
7805
0
SLANG_RAW("    __target_switch\n")
7806
0
SLANG_RAW("    {\n")
7807
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_acosh($0)\";\n")
7808
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_acosh($0)\";\n")
7809
0
SLANG_RAW("    case glsl: __intrinsic_asm \"acosh\";\n")
7810
0
SLANG_RAW("    case metal: __intrinsic_asm \"acosh\";\n")
7811
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7812
0
SLANG_RAW("        OpExtInst $$T result glsl450 Acosh $x\n")
7813
0
SLANG_RAW("    };\n")
7814
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"acosh\";\n")
7815
0
SLANG_RAW("    default:\n")
7816
0
SLANG_RAW("        return log(x + sqrt( x * x - T(1)));\n")
7817
0
SLANG_RAW("    }\n")
7818
0
SLANG_RAW("}\n")
7819
0
SLANG_RAW("\n")
7820
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N:int>\n")
7821
0
SLANG_RAW("[__readNone]\n")
7822
0
SLANG_RAW("[ForceInline]\n")
7823
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7824
0
SLANG_RAW("vector<T,N> acosh(vector<T,N> x)\n")
7825
0
SLANG_RAW("{\n")
7826
0
SLANG_RAW("    __target_switch\n")
7827
0
SLANG_RAW("    {\n")
7828
0
SLANG_RAW("    case glsl: __intrinsic_asm \"acosh\";\n")
7829
0
SLANG_RAW("    case metal: __intrinsic_asm \"acosh\";\n")
7830
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
7831
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Acosh $x\n")
7832
0
SLANG_RAW("    };\n")
7833
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"acosh\";\n")
7834
0
SLANG_RAW("    default:\n")
7835
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, acosh, x);\n")
7836
0
SLANG_RAW("    }\n")
7837
0
SLANG_RAW("}\n")
7838
0
SLANG_RAW("\n")
7839
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
7840
0
SLANG_RAW("[__readNone]\n")
7841
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
7842
0
SLANG_RAW("matrix<T, N, M> acosh(matrix<T, N, M> x)\n")
7843
0
SLANG_RAW("{\n")
7844
0
SLANG_RAW("    __target_switch\n")
7845
0
SLANG_RAW("    {\n")
7846
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"acosh\";\n")
7847
0
SLANG_RAW("    default:\n")
7848
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, acosh, x);\n")
7849
0
SLANG_RAW("    }\n")
7850
0
SLANG_RAW("}\n")
7851
0
SLANG_RAW("\n")
7852
0
SLANG_RAW("// Test if all components are non-zero.\n")
7853
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
7854
0
SLANG_RAW("[__readNone]\n")
7855
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7856
0
SLANG_RAW("bool all(T x)\n")
7857
0
SLANG_RAW("{\n")
7858
0
SLANG_RAW("    __target_switch\n")
7859
0
SLANG_RAW("    {\n")
7860
0
SLANG_RAW("    case hlsl:\n")
7861
0
SLANG_RAW("        __intrinsic_asm \"all\";\n")
7862
0
SLANG_RAW("    case metal:\n")
7863
0
SLANG_RAW("        __intrinsic_asm \"all\";\n")
7864
0
SLANG_RAW("    case spirv:\n")
7865
0
SLANG_RAW("        let zero = __default<T>();\n")
7866
0
SLANG_RAW("        if (__isInt<T>())\n")
7867
0
SLANG_RAW("            return spirv_asm\n")
7868
0
SLANG_RAW("            {\n")
7869
0
SLANG_RAW("                OpINotEqual $$bool result $x $zero\n")
7870
0
SLANG_RAW("            };\n")
7871
0
SLANG_RAW("        else if (__isFloat<T>())\n")
7872
0
SLANG_RAW("            return spirv_asm\n")
7873
0
SLANG_RAW("            {\n")
7874
0
SLANG_RAW("                OpFUnordNotEqual $$bool result $x $zero\n")
7875
0
SLANG_RAW("            };\n")
7876
0
SLANG_RAW("        else if (__isBool<T>())\n")
7877
0
SLANG_RAW("            return __slang_noop_cast<bool>(x);\n")
7878
0
SLANG_RAW("        else\n")
7879
0
SLANG_RAW("            return false;\n")
7880
0
SLANG_RAW("    default:\n")
7881
0
SLANG_RAW("        __intrinsic_asm \"bool($0)\";\n")
7882
0
SLANG_RAW("    }\n")
7883
0
SLANG_RAW("}\n")
7884
0
SLANG_RAW("\n")
7885
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
7886
0
SLANG_RAW("[__readNone]\n")
7887
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7888
0
SLANG_RAW("bool all(vector<T,N> x)\n")
7889
0
SLANG_RAW("{\n")
7890
0
SLANG_RAW("    if(N == 1)\n")
7891
0
SLANG_RAW("        return all(x[0]);\n")
7892
0
SLANG_RAW("    __target_switch\n")
7893
0
SLANG_RAW("    {\n")
7894
0
SLANG_RAW("    case hlsl:\n")
7895
0
SLANG_RAW("        __intrinsic_asm \"all\";\n")
7896
0
SLANG_RAW("    case metal:\n")
7897
0
SLANG_RAW("        if (__isBool<T>())\n")
7898
0
SLANG_RAW("            __intrinsic_asm \"all\";\n")
7899
0
SLANG_RAW("        __intrinsic_asm \"all(bool$N0($0))\";\n")
7900
0
SLANG_RAW("    case glsl:\n")
7901
0
SLANG_RAW("        __intrinsic_asm \"all(bvec$N0($0))\";\n")
7902
0
SLANG_RAW("    case spirv:\n")
7903
0
SLANG_RAW("        if (__isBool<T>())\n")
7904
0
SLANG_RAW("            return spirv_asm\n")
7905
0
SLANG_RAW("            {\n")
7906
0
SLANG_RAW("                OpAll $$bool result $x\n")
7907
0
SLANG_RAW("            };\n")
7908
0
SLANG_RAW("        else if (__isInt<T>())\n")
7909
0
SLANG_RAW("        {\n")
7910
0
SLANG_RAW("            let zero = __default<vector<T,N>>();\n")
7911
0
SLANG_RAW("            return spirv_asm\n")
7912
0
SLANG_RAW("            {\n")
7913
0
SLANG_RAW("                OpINotEqual $$vector<bool,N> %castResult $x $zero;\n")
7914
0
SLANG_RAW("                OpAll $$bool result %castResult\n")
7915
0
SLANG_RAW("            };\n")
7916
0
SLANG_RAW("        }\n")
7917
0
SLANG_RAW("        else\n")
7918
0
SLANG_RAW("        {\n")
7919
0
SLANG_RAW("            let zero = __default<vector<T,N>>();\n")
7920
0
SLANG_RAW("            return spirv_asm\n")
7921
0
SLANG_RAW("            {\n")
7922
0
SLANG_RAW("                OpFUnordNotEqual $$vector<bool,N> %castResult $x $zero;\n")
7923
0
SLANG_RAW("                OpAll $$bool result %castResult\n")
7924
0
SLANG_RAW("            };\n")
7925
0
SLANG_RAW("        }\n")
7926
0
SLANG_RAW("    case wgsl:\n")
7927
0
SLANG_RAW("        // WGSL all() only works with boolean vectors\n")
7928
0
SLANG_RAW("        if (__isBool<T>())\n")
7929
0
SLANG_RAW("            __intrinsic_asm \"all($0)\";\n")
7930
0
SLANG_RAW("        else\n")
7931
0
SLANG_RAW("        {\n")
7932
0
SLANG_RAW("            // Fall back to loop for non-boolean types since WGSL doesn't support direct conversion\n")
7933
0
SLANG_RAW("            bool result = true;\n")
7934
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
7935
0
SLANG_RAW("                result = result && all(x[i]);\n")
7936
0
SLANG_RAW("            return result;\n")
7937
0
SLANG_RAW("        }\n")
7938
0
SLANG_RAW("    default:\n")
7939
0
SLANG_RAW("        bool result = true;\n")
7940
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
7941
0
SLANG_RAW("            result = result && all(x[i]);\n")
7942
0
SLANG_RAW("        return result;\n")
7943
0
SLANG_RAW("    }\n")
7944
0
SLANG_RAW("}\n")
7945
0
SLANG_RAW("\n")
7946
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
7947
0
SLANG_RAW("[__readNone]\n")
7948
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
7949
0
SLANG_RAW("bool all(matrix<T,N,M> x)\n")
7950
0
SLANG_RAW("{\n")
7951
0
SLANG_RAW("    __target_switch\n")
7952
0
SLANG_RAW("    {\n")
7953
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"all\";\n")
7954
0
SLANG_RAW("    default:\n")
7955
0
SLANG_RAW("        bool result = true;\n")
7956
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
7957
0
SLANG_RAW("            result = result && all(x[i]);\n")
7958
0
SLANG_RAW("        return result;\n")
7959
0
SLANG_RAW("    }\n")
7960
0
SLANG_RAW("}\n")
7961
0
SLANG_RAW("\n")
7962
0
SLANG_RAW("/// Barrier for writes to all memory spaces.\n")
7963
0
SLANG_RAW("/// @category barrier Memory and control barriers\n")
7964
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
7965
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
7966
0
SLANG_RAW("void AllMemoryBarrier()\n")
7967
0
SLANG_RAW("{\n")
7968
0
SLANG_RAW("    __target_switch\n")
7969
0
SLANG_RAW("    {\n")
7970
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"AllMemoryBarrier\";\n")
7971
0
SLANG_RAW("    case glsl: __intrinsic_asm \"memoryBarrier(gl_ScopeDevice, (gl_StorageSemanticsShared|gl_StorageSemanticsImage|gl_StorageSemanticsBuffer), gl_SemanticsAcquireRelease)\";\n")
7972
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__threadfence()\";\n")
7973
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup | mem_flags::mem_texture | mem_flags::mem_threadgroup_imageblock)\";\n")
7974
0
SLANG_RAW("    case spirv: spirv_asm\n")
7975
0
SLANG_RAW("        {\n")
7976
0
SLANG_RAW("            OpMemoryBarrier Device AcquireRelease|UniformMemory|WorkgroupMemory|ImageMemory;\n")
7977
0
SLANG_RAW("        };\n")
7978
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"storageBarrier(); textureBarrier(); workgroupBarrier();\";\n")
7979
0
SLANG_RAW("    }\n")
7980
0
SLANG_RAW("}\n")
7981
0
SLANG_RAW("\n")
7982
0
SLANG_RAW("/// Thread-group sync and barrier for writes to all memory spaces.\n")
7983
0
SLANG_RAW("/// @category barrier\n")
7984
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
7985
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
7986
0
SLANG_RAW("void AllMemoryBarrierWithGroupSync()\n")
7987
0
SLANG_RAW("{\n")
7988
0
SLANG_RAW("    __target_switch\n")
7989
0
SLANG_RAW("    {\n")
7990
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"AllMemoryBarrierWithGroupSync\";\n")
7991
0
SLANG_RAW("    case glsl: __intrinsic_asm \"controlBarrier(gl_ScopeWorkgroup, gl_ScopeDevice, (gl_StorageSemanticsShared|gl_StorageSemanticsImage|gl_StorageSemanticsBuffer), gl_SemanticsAcquireRelease)\";\n")
7992
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__syncthreads()\";\n")
7993
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup | mem_flags::mem_texture | mem_flags::mem_threadgroup_imageblock)\";\n")
7994
0
SLANG_RAW("    case spirv: spirv_asm\n")
7995
0
SLANG_RAW("        {\n")
7996
0
SLANG_RAW("            OpControlBarrier Workgroup Device AcquireRelease|UniformMemory|WorkgroupMemory|ImageMemory;\n")
7997
0
SLANG_RAW("        };\n")
7998
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"storageBarrier(); textureBarrier(); workgroupBarrier();\";\n")
7999
0
SLANG_RAW("    }\n")
8000
0
SLANG_RAW("}\n")
8001
0
SLANG_RAW("\n")
8002
0
SLANG_RAW("// Returns the workgroup size of the calling entry point.\n")
8003
0
SLANG_RAW("[require(compute)]\n")
8004
0
SLANG_RAW("[require(meshshading)]\n")
8005
0
SLANG_RAW("__intrinsic_op(")
8006
0
SLANG_SPLICE(kIROp_GetWorkGroupSize
8007
0
)
8008
0
SLANG_RAW(")\n")
8009
0
SLANG_RAW("int3 WorkgroupSize();\n")
8010
0
SLANG_RAW("\n")
8011
0
SLANG_RAW("// Returns number of workgroups that have been dispatched to a GLSL or SPIR-V compute shader\n")
8012
0
SLANG_RAW("[require(glsl_spirv, GLSL_430_SPIRV_1_0_compute)]\n")
8013
0
SLANG_RAW("[require(glsl_spirv, meshshading)]\n")
8014
0
SLANG_RAW("uint3 WorkgroupCount()\n")
8015
0
SLANG_RAW("{\n")
8016
0
SLANG_RAW("    __target_switch\n")
8017
0
SLANG_RAW("    {\n")
8018
0
SLANG_RAW("    case glsl:\n")
8019
0
SLANG_RAW("        __intrinsic_asm \"(gl_NumWorkGroups)\";\n")
8020
0
SLANG_RAW("    case spirv:\n")
8021
0
SLANG_RAW("        return spirv_asm {\n")
8022
0
SLANG_RAW("            result:$$uint3 = OpLoad builtin(NumWorkgroups:uint3);\n")
8023
0
SLANG_RAW("        };\n")
8024
0
SLANG_RAW("    }\n")
8025
0
SLANG_RAW("}\n")
8026
0
SLANG_RAW("\n")
8027
0
SLANG_RAW("// Test if any components is non-zero.\n")
8028
0
SLANG_RAW("\n")
8029
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
8030
0
SLANG_RAW("[__readNone]\n")
8031
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
8032
0
SLANG_RAW("bool any(T x)\n")
8033
0
SLANG_RAW("{\n")
8034
0
SLANG_RAW("    __target_switch\n")
8035
0
SLANG_RAW("    {\n")
8036
0
SLANG_RAW("    default:\n")
8037
0
SLANG_RAW("        __intrinsic_asm \"bool($0)\";\n")
8038
0
SLANG_RAW("    case hlsl:\n")
8039
0
SLANG_RAW("        __intrinsic_asm \"any\";\n")
8040
0
SLANG_RAW("    case metal:\n")
8041
0
SLANG_RAW("        __intrinsic_asm \"any\";\n")
8042
0
SLANG_RAW("    case wgsl:\n")
8043
0
SLANG_RAW("        // For scalars, any() doesn't exist in WGSL, just convert to bool\n")
8044
0
SLANG_RAW("        __intrinsic_asm \"bool($0)\";\n")
8045
0
SLANG_RAW("    case spirv:\n")
8046
0
SLANG_RAW("        let zero = __default<T>();\n")
8047
0
SLANG_RAW("        if (__isInt<T>())\n")
8048
0
SLANG_RAW("            return spirv_asm\n")
8049
0
SLANG_RAW("            {\n")
8050
0
SLANG_RAW("                OpINotEqual $$bool result $x $zero\n")
8051
0
SLANG_RAW("            };\n")
8052
0
SLANG_RAW("        else if (__isFloat<T>())\n")
8053
0
SLANG_RAW("            return spirv_asm\n")
8054
0
SLANG_RAW("            {\n")
8055
0
SLANG_RAW("                OpFUnordNotEqual $$bool result $x $zero\n")
8056
0
SLANG_RAW("            };\n")
8057
0
SLANG_RAW("        else if (__isBool<T>())\n")
8058
0
SLANG_RAW("            return __slang_noop_cast<bool>(x);\n")
8059
0
SLANG_RAW("        return false;\n")
8060
0
SLANG_RAW("    }\n")
8061
0
SLANG_RAW("}\n")
8062
0
SLANG_RAW("\n")
8063
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
8064
0
SLANG_RAW("[__readNone]\n")
8065
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
8066
0
SLANG_RAW("bool any(vector<T, N> x)\n")
8067
0
SLANG_RAW("{\n")
8068
0
SLANG_RAW("    if(N == 1)\n")
8069
0
SLANG_RAW("        return any(x[0]);\n")
8070
0
SLANG_RAW("    __target_switch\n")
8071
0
SLANG_RAW("    {\n")
8072
0
SLANG_RAW("    case hlsl:\n")
8073
0
SLANG_RAW("        __intrinsic_asm \"any\";\n")
8074
0
SLANG_RAW("    case metal:\n")
8075
0
SLANG_RAW("        if (__isBool<T>())\n")
8076
0
SLANG_RAW("            __intrinsic_asm \"any\";\n")
8077
0
SLANG_RAW("        else\n")
8078
0
SLANG_RAW("        {\n")
8079
0
SLANG_RAW("            // For non-bool types, convert to bool vector first\n")
8080
0
SLANG_RAW("            // Metal's any() only works with bool vectors\n")
8081
0
SLANG_RAW("            bool result = false;\n")
8082
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
8083
0
SLANG_RAW("                result = result || any(x[i]);\n")
8084
0
SLANG_RAW("            return result;\n")
8085
0
SLANG_RAW("        }\n")
8086
0
SLANG_RAW("    case glsl:\n")
8087
0
SLANG_RAW("        __intrinsic_asm \"any(bvec$N0($0))\";\n")
8088
0
SLANG_RAW("    case spirv:\n")
8089
0
SLANG_RAW("        if (__isBool<T>())\n")
8090
0
SLANG_RAW("            return spirv_asm\n")
8091
0
SLANG_RAW("            {\n")
8092
0
SLANG_RAW("                OpAny $$bool result $x\n")
8093
0
SLANG_RAW("            };\n")
8094
0
SLANG_RAW("        else if (__isInt<T>())\n")
8095
0
SLANG_RAW("        {\n")
8096
0
SLANG_RAW("            let zero = __default<vector<T,N>>();\n")
8097
0
SLANG_RAW("            return spirv_asm\n")
8098
0
SLANG_RAW("            {\n")
8099
0
SLANG_RAW("                OpINotEqual $$vector<bool,N> %castResult $x $zero;\n")
8100
0
SLANG_RAW("                OpAny $$bool result %castResult\n")
8101
0
SLANG_RAW("            };\n")
8102
0
SLANG_RAW("        }\n")
8103
0
SLANG_RAW("        else\n")
8104
0
SLANG_RAW("        {\n")
8105
0
SLANG_RAW("            let zero = __default<vector<T,N>>();\n")
8106
0
SLANG_RAW("            return spirv_asm\n")
8107
0
SLANG_RAW("            {\n")
8108
0
SLANG_RAW("                OpFUnordNotEqual $$vector<bool,N> %castResult $x $zero;\n")
8109
0
SLANG_RAW("                OpAny $$bool result %castResult\n")
8110
0
SLANG_RAW("            };\n")
8111
0
SLANG_RAW("        }\n")
8112
0
SLANG_RAW("    case wgsl:\n")
8113
0
SLANG_RAW("        // WGSL any() only works with boolean vectors\n")
8114
0
SLANG_RAW("        if (__isBool<T>())\n")
8115
0
SLANG_RAW("            __intrinsic_asm \"any($0)\";\n")
8116
0
SLANG_RAW("        else\n")
8117
0
SLANG_RAW("        {\n")
8118
0
SLANG_RAW("            // Fall back to loop for non-boolean types since WGSL doesn't support direct conversion\n")
8119
0
SLANG_RAW("            bool result = false;\n")
8120
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
8121
0
SLANG_RAW("                result = result || any(x[i]);\n")
8122
0
SLANG_RAW("            return result;\n")
8123
0
SLANG_RAW("        }\n")
8124
0
SLANG_RAW("    default:\n")
8125
0
SLANG_RAW("        bool result = false;\n")
8126
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
8127
0
SLANG_RAW("            result = result || any(x[i]);\n")
8128
0
SLANG_RAW("        return result;\n")
8129
0
SLANG_RAW("    }\n")
8130
0
SLANG_RAW("}\n")
8131
0
SLANG_RAW("\n")
8132
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
8133
0
SLANG_RAW("[__readNone]\n")
8134
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
8135
0
SLANG_RAW("bool any(matrix<T, N, M> x)\n")
8136
0
SLANG_RAW("{\n")
8137
0
SLANG_RAW("    __target_switch\n")
8138
0
SLANG_RAW("    {\n")
8139
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"any\";\n")
8140
0
SLANG_RAW("    default:\n")
8141
0
SLANG_RAW("        bool result = false;\n")
8142
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
8143
0
SLANG_RAW("            result = result || any(x[i]);\n")
8144
0
SLANG_RAW("        return result;\n")
8145
0
SLANG_RAW("    }\n")
8146
0
SLANG_RAW("}\n")
8147
0
SLANG_RAW("\n")
8148
0
SLANG_RAW("\n")
8149
0
SLANG_RAW("/// Reinterpret bits as a double.\n")
8150
0
SLANG_RAW("/// @category conversion\n")
8151
0
SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader5)\n")
8152
0
SLANG_RAW("[__readNone]\n")
8153
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8154
0
SLANG_RAW("double asdouble(uint lowbits, uint highbits)\n")
8155
0
SLANG_RAW("{\n")
8156
0
SLANG_RAW("    __target_switch\n")
8157
0
SLANG_RAW("    {\n")
8158
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asdouble\";\n")
8159
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packDouble2x32(uvec2($0, $1))\";\n")
8160
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asdouble($0, $1)\";\n")
8161
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asdouble($0, $1)\";\n")
8162
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8163
0
SLANG_RAW("        %v:$$uint2 = OpCompositeConstruct $lowbits $highbits;\n")
8164
0
SLANG_RAW("        result:$$double = OpExtInst glsl450 59 %v\n")
8165
0
SLANG_RAW("    };\n")
8166
0
SLANG_RAW("    }\n")
8167
0
SLANG_RAW("}\n")
8168
0
SLANG_RAW("\n")
8169
0
SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader5)\n")
8170
0
SLANG_RAW("[__readNone]\n")
8171
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8172
0
SLANG_RAW("double2 asdouble(uint2 lowbits, uint2 highbits)\n")
8173
0
SLANG_RAW("{\n")
8174
0
SLANG_RAW("    __target_switch\n")
8175
0
SLANG_RAW("    {\n")
8176
0
SLANG_RAW("    case hlsl:\n")
8177
0
SLANG_RAW("        __intrinsic_asm \"asdouble($0, $1)\";\n")
8178
0
SLANG_RAW("    default:\n")
8179
0
SLANG_RAW("        return double2(asdouble(lowbits.x, highbits.x), asdouble(lowbits.y, highbits.y));\n")
8180
0
SLANG_RAW("    }\n")
8181
0
SLANG_RAW("}\n")
8182
0
SLANG_RAW("\n")
8183
0
SLANG_RAW("/// Reinterpret bits as a float.\n")
8184
0
SLANG_RAW("/// @category conversion\n")
8185
0
SLANG_RAW("[__readNone]\n")
8186
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8187
0
SLANG_RAW("float asfloat(int x)\n")
8188
0
SLANG_RAW("{\n")
8189
0
SLANG_RAW("    __target_switch\n")
8190
0
SLANG_RAW("    {\n")
8191
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asfloat($0)\";\n")
8192
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asfloat($0)\";\n")
8193
0
SLANG_RAW("    case glsl: __intrinsic_asm \"intBitsToFloat\";\n")
8194
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8195
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8196
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8197
0
SLANG_RAW("        OpBitcast $$float result $x\n")
8198
0
SLANG_RAW("    };\n")
8199
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8200
0
SLANG_RAW("    }\n")
8201
0
SLANG_RAW("}\n")
8202
0
SLANG_RAW("\n")
8203
0
SLANG_RAW("[__readNone]\n")
8204
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8205
0
SLANG_RAW("float asfloat(uint x)\n")
8206
0
SLANG_RAW("{\n")
8207
0
SLANG_RAW("    __target_switch\n")
8208
0
SLANG_RAW("    {\n")
8209
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asfloat($0)\";\n")
8210
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asfloat($0)\";\n")
8211
0
SLANG_RAW("    case glsl: __intrinsic_asm \"uintBitsToFloat\";\n")
8212
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8213
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8214
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8215
0
SLANG_RAW("        OpBitcast $$float result $x\n")
8216
0
SLANG_RAW("    };\n")
8217
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8218
0
SLANG_RAW("    }\n")
8219
0
SLANG_RAW("}\n")
8220
0
SLANG_RAW("\n")
8221
0
SLANG_RAW("__generic<let N : int>\n")
8222
0
SLANG_RAW("[__readNone]\n")
8223
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8224
0
SLANG_RAW("vector<float, N> asfloat(vector< int, N> x)\n")
8225
0
SLANG_RAW("{\n")
8226
0
SLANG_RAW("    __target_switch\n")
8227
0
SLANG_RAW("    {\n")
8228
0
SLANG_RAW("    case glsl: __intrinsic_asm \"intBitsToFloat\";\n")
8229
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8230
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8231
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8232
0
SLANG_RAW("        OpBitcast $$vector<float, N> result $x\n")
8233
0
SLANG_RAW("    };\n")
8234
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8235
0
SLANG_RAW("    default:\n")
8236
0
SLANG_RAW("        VECTOR_MAP_UNARY(float, N, asfloat, x);\n")
8237
0
SLANG_RAW("    }\n")
8238
0
SLANG_RAW("}\n")
8239
0
SLANG_RAW("\n")
8240
0
SLANG_RAW("__generic<let N : int>\n")
8241
0
SLANG_RAW("[__readNone]\n")
8242
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8243
0
SLANG_RAW("vector<float,N> asfloat(vector<uint,N> x)\n")
8244
0
SLANG_RAW("{\n")
8245
0
SLANG_RAW("    __target_switch\n")
8246
0
SLANG_RAW("    {\n")
8247
0
SLANG_RAW("    case glsl: __intrinsic_asm \"uintBitsToFloat\";\n")
8248
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8249
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8250
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8251
0
SLANG_RAW("        OpBitcast $$vector<float,N> result $x\n")
8252
0
SLANG_RAW("    };\n")
8253
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8254
0
SLANG_RAW("    default:\n")
8255
0
SLANG_RAW("        VECTOR_MAP_UNARY(float, N, asfloat, x);\n")
8256
0
SLANG_RAW("    }\n")
8257
0
SLANG_RAW("}\n")
8258
0
SLANG_RAW("\n")
8259
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8260
0
SLANG_RAW("[__readNone]\n")
8261
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8262
0
SLANG_RAW("matrix<float,N,M> asfloat(matrix< int,N,M> x)\n")
8263
0
SLANG_RAW("{\n")
8264
0
SLANG_RAW("    __target_switch\n")
8265
0
SLANG_RAW("    {\n")
8266
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8267
0
SLANG_RAW("    default:\n")
8268
0
SLANG_RAW("        MATRIX_MAP_UNARY(float, N, M, asfloat, x);\n")
8269
0
SLANG_RAW("    }\n")
8270
0
SLANG_RAW("}\n")
8271
0
SLANG_RAW("\n")
8272
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8273
0
SLANG_RAW("[__readNone]\n")
8274
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8275
0
SLANG_RAW("matrix<float,N,M> asfloat(matrix<uint,N,M> x)\n")
8276
0
SLANG_RAW("{\n")
8277
0
SLANG_RAW("    __target_switch\n")
8278
0
SLANG_RAW("    {\n")
8279
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat\";\n")
8280
0
SLANG_RAW("    default:\n")
8281
0
SLANG_RAW("        MATRIX_MAP_UNARY(float, N, M, asfloat, x);\n")
8282
0
SLANG_RAW("    }\n")
8283
0
SLANG_RAW("}\n")
8284
0
SLANG_RAW("\n")
8285
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8286
0
SLANG_RAW("[__readNone]\n")
8287
0
SLANG_RAW("float asfloat(float x)\n")
8288
0
SLANG_RAW("{ return x; }\n")
8289
0
SLANG_RAW("\n")
8290
0
SLANG_RAW("__generic<let N : int>\n")
8291
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8292
0
SLANG_RAW("[__readNone]\n")
8293
0
SLANG_RAW("vector<float,N> asfloat(vector<float,N> x)\n")
8294
0
SLANG_RAW("{ return x; }\n")
8295
0
SLANG_RAW("\n")
8296
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8297
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8298
0
SLANG_RAW("[__readNone]\n")
8299
0
SLANG_RAW("matrix<float,N,M> asfloat(matrix<float,N,M> x)\n")
8300
0
SLANG_RAW("{ return x; }\n")
8301
0
SLANG_RAW("\n")
8302
0
SLANG_RAW("/// Arc sine. Returns the angle whose sine is the specified number.\n")
8303
0
SLANG_RAW("/// @param x The sine value.\n")
8304
0
SLANG_RAW("/// @return The angle in radians, in the range of [-pi/2, pi/2].\n")
8305
0
SLANG_RAW("/// @category math\n")
8306
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
8307
0
SLANG_RAW("[__readNone]\n")
8308
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8309
0
SLANG_RAW("T asin(T x)\n")
8310
0
SLANG_RAW("{\n")
8311
0
SLANG_RAW("    __target_switch\n")
8312
0
SLANG_RAW("    {\n")
8313
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asin($0)\";\n")
8314
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asin($0)\";\n")
8315
0
SLANG_RAW("    case glsl: __intrinsic_asm \"asin\";\n")
8316
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asin\";\n")
8317
0
SLANG_RAW("    case metal: __intrinsic_asm \"asin\";\n")
8318
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8319
0
SLANG_RAW("        OpExtInst $$T result glsl450 Asin $x\n")
8320
0
SLANG_RAW("    };\n")
8321
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"asin\";\n")
8322
0
SLANG_RAW("    }\n")
8323
0
SLANG_RAW("}\n")
8324
0
SLANG_RAW("\n")
8325
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
8326
0
SLANG_RAW("[__readNone]\n")
8327
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8328
0
SLANG_RAW("vector<T, N> asin(vector<T, N> x)\n")
8329
0
SLANG_RAW("{\n")
8330
0
SLANG_RAW("    __target_switch\n")
8331
0
SLANG_RAW("    {\n")
8332
0
SLANG_RAW("    case glsl: __intrinsic_asm \"asin\";\n")
8333
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asin\";\n")
8334
0
SLANG_RAW("    case metal: __intrinsic_asm \"asin\";\n")
8335
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8336
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Asin $x\n")
8337
0
SLANG_RAW("    };\n")
8338
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"asin\";\n")
8339
0
SLANG_RAW("    default:\n")
8340
0
SLANG_RAW("        VECTOR_MAP_UNARY(T,N,asin,x);\n")
8341
0
SLANG_RAW("    }\n")
8342
0
SLANG_RAW("}\n")
8343
0
SLANG_RAW("\n")
8344
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
8345
0
SLANG_RAW("[__readNone]\n")
8346
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8347
0
SLANG_RAW("matrix<T, N, M> asin(matrix<T, N, M> x)\n")
8348
0
SLANG_RAW("{\n")
8349
0
SLANG_RAW("    __target_switch\n")
8350
0
SLANG_RAW("    {\n")
8351
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asin\";\n")
8352
0
SLANG_RAW("    default:\n")
8353
0
SLANG_RAW("        MATRIX_MAP_UNARY(T,N,M,asin,x);\n")
8354
0
SLANG_RAW("    }\n")
8355
0
SLANG_RAW("}\n")
8356
0
SLANG_RAW("\n")
8357
0
SLANG_RAW("/// Arc hyperbolic sine. Returns the arc hyperbolic sine of the specified value.\n")
8358
0
SLANG_RAW("/// @param x The hyperbolic sine value.\n")
8359
0
SLANG_RAW("/// @return The arc hyperbolic sine of the specified value.\n")
8360
0
SLANG_RAW("/// @category math\n")
8361
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
8362
0
SLANG_RAW("[__readNone]\n")
8363
0
SLANG_RAW("[ForceInline]\n")
8364
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8365
0
SLANG_RAW("T asinh(T x)\n")
8366
0
SLANG_RAW("{\n")
8367
0
SLANG_RAW("    __target_switch\n")
8368
0
SLANG_RAW("    {\n")
8369
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asinh($0)\";\n")
8370
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asinh($0)\";\n")
8371
0
SLANG_RAW("    case glsl: __intrinsic_asm \"asinh\";\n")
8372
0
SLANG_RAW("    case metal: __intrinsic_asm \"asinh\";\n")
8373
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8374
0
SLANG_RAW("        OpExtInst $$T result glsl450 Asinh $x\n")
8375
0
SLANG_RAW("    };\n")
8376
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"asinh\";\n")
8377
0
SLANG_RAW("    default:\n")
8378
0
SLANG_RAW("        return log(x + sqrt(x * x + T(1)));\n")
8379
0
SLANG_RAW("    }\n")
8380
0
SLANG_RAW("}\n")
8381
0
SLANG_RAW("\n")
8382
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N:int>\n")
8383
0
SLANG_RAW("[__readNone]\n")
8384
0
SLANG_RAW("[ForceInline]\n")
8385
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8386
0
SLANG_RAW("vector<T,N> asinh(vector<T,N> x)\n")
8387
0
SLANG_RAW("{\n")
8388
0
SLANG_RAW("    __target_switch\n")
8389
0
SLANG_RAW("    {\n")
8390
0
SLANG_RAW("    case glsl: __intrinsic_asm \"asinh\";\n")
8391
0
SLANG_RAW("    case metal: __intrinsic_asm \"asinh\";\n")
8392
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8393
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Asinh $x\n")
8394
0
SLANG_RAW("    };\n")
8395
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"asinh\";\n")
8396
0
SLANG_RAW("    default:\n")
8397
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, asinh, x);\n")
8398
0
SLANG_RAW("    }\n")
8399
0
SLANG_RAW("}\n")
8400
0
SLANG_RAW("\n")
8401
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
8402
0
SLANG_RAW("[__readNone]\n")
8403
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8404
0
SLANG_RAW("matrix<T, N, M> asinh(matrix<T, N, M> x)\n")
8405
0
SLANG_RAW("{\n")
8406
0
SLANG_RAW("    __target_switch\n")
8407
0
SLANG_RAW("    {\n")
8408
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asinh\";\n")
8409
0
SLANG_RAW("    default:\n")
8410
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, asinh, x);\n")
8411
0
SLANG_RAW("    }\n")
8412
0
SLANG_RAW("}\n")
8413
0
SLANG_RAW("\n")
8414
0
SLANG_RAW("/// Reinterpret bits as an int.\n")
8415
0
SLANG_RAW("/// @category conversion\n")
8416
0
SLANG_RAW("[__readNone]\n")
8417
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8418
0
SLANG_RAW("int asint(float x)\n")
8419
0
SLANG_RAW("{\n")
8420
0
SLANG_RAW("    __target_switch\n")
8421
0
SLANG_RAW("    {\n")
8422
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asint($0)\";\n")
8423
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asint($0)\";\n")
8424
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floatBitsToInt\";\n")
8425
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8426
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8427
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8428
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8429
0
SLANG_RAW("        OpBitcast $$int result $x\n")
8430
0
SLANG_RAW("    };\n")
8431
0
SLANG_RAW("    }\n")
8432
0
SLANG_RAW("}\n")
8433
0
SLANG_RAW("\n")
8434
0
SLANG_RAW("[__readNone]\n")
8435
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8436
0
SLANG_RAW("int asint(uint x)\n")
8437
0
SLANG_RAW("{\n")
8438
0
SLANG_RAW("    __target_switch\n")
8439
0
SLANG_RAW("    {\n")
8440
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asint($0)\";\n")
8441
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asint($0)\";\n")
8442
0
SLANG_RAW("    case glsl: __intrinsic_asm \"int($0)\";\n")
8443
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8444
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8445
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8446
0
SLANG_RAW("        OpBitcast $$int result $x\n")
8447
0
SLANG_RAW("    };\n")
8448
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8449
0
SLANG_RAW("    }\n")
8450
0
SLANG_RAW("}\n")
8451
0
SLANG_RAW("\n")
8452
0
SLANG_RAW("__generic<let N : int>\n")
8453
0
SLANG_RAW("[__readNone]\n")
8454
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8455
0
SLANG_RAW("vector<int, N> asint(vector<float, N> x)\n")
8456
0
SLANG_RAW("{\n")
8457
0
SLANG_RAW("    __target_switch\n")
8458
0
SLANG_RAW("    {\n")
8459
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floatBitsToInt\";\n")
8460
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8461
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8462
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8463
0
SLANG_RAW("        OpBitcast $$vector<int, N> result $x\n")
8464
0
SLANG_RAW("    };\n")
8465
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8466
0
SLANG_RAW("    default:\n")
8467
0
SLANG_RAW("        VECTOR_MAP_UNARY(int, N, asint, x);\n")
8468
0
SLANG_RAW("    }\n")
8469
0
SLANG_RAW("}\n")
8470
0
SLANG_RAW("\n")
8471
0
SLANG_RAW("__generic<let N : int>\n")
8472
0
SLANG_RAW("[__readNone]\n")
8473
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8474
0
SLANG_RAW("vector<int, N> asint(vector<uint, N> x)\n")
8475
0
SLANG_RAW("{\n")
8476
0
SLANG_RAW("    if(N == 1)\n")
8477
0
SLANG_RAW("        return vector<int, N>(asint(x[0]));\n")
8478
0
SLANG_RAW("    __target_switch\n")
8479
0
SLANG_RAW("    {\n")
8480
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ivec$N0($0)\";\n")
8481
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8482
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8483
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8484
0
SLANG_RAW("        OpBitcast $$vector<int, N> result $x\n")
8485
0
SLANG_RAW("    };\n")
8486
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8487
0
SLANG_RAW("    default:\n")
8488
0
SLANG_RAW("        VECTOR_MAP_UNARY(int, N, asint, x);\n")
8489
0
SLANG_RAW("    }\n")
8490
0
SLANG_RAW("}\n")
8491
0
SLANG_RAW("\n")
8492
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8493
0
SLANG_RAW("[__readNone]\n")
8494
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_4_0)]\n")
8495
0
SLANG_RAW("matrix<int, N, M> asint(matrix<float, N, M> x)\n")
8496
0
SLANG_RAW("{\n")
8497
0
SLANG_RAW("    __target_switch\n")
8498
0
SLANG_RAW("    {\n")
8499
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8500
0
SLANG_RAW("    default:\n")
8501
0
SLANG_RAW("        MATRIX_MAP_UNARY(int, N, M, asint, x);\n")
8502
0
SLANG_RAW("    }\n")
8503
0
SLANG_RAW("}\n")
8504
0
SLANG_RAW("\n")
8505
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8506
0
SLANG_RAW("[__readNone]\n")
8507
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_4_0)]\n")
8508
0
SLANG_RAW("matrix<int, N, M> asint(matrix<uint, N, M> x)\n")
8509
0
SLANG_RAW("{\n")
8510
0
SLANG_RAW("    __target_switch\n")
8511
0
SLANG_RAW("    {\n")
8512
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint\";\n")
8513
0
SLANG_RAW("    default:\n")
8514
0
SLANG_RAW("        MATRIX_MAP_UNARY(int, N, M, asint, x);\n")
8515
0
SLANG_RAW("    }\n")
8516
0
SLANG_RAW("}\n")
8517
0
SLANG_RAW("\n")
8518
0
SLANG_RAW("// No op\n")
8519
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8520
0
SLANG_RAW("[__readNone]\n")
8521
0
SLANG_RAW("int asint(int x)\n")
8522
0
SLANG_RAW("{ return x; }\n")
8523
0
SLANG_RAW("\n")
8524
0
SLANG_RAW("__generic<let N : int>\n")
8525
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8526
0
SLANG_RAW("[__readNone]\n")
8527
0
SLANG_RAW("vector<int,N> asint(vector<int,N> x)\n")
8528
0
SLANG_RAW("{ return x; }\n")
8529
0
SLANG_RAW("\n")
8530
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8531
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8532
0
SLANG_RAW("[__readNone]\n")
8533
0
SLANG_RAW("matrix<int,N,M> asint(matrix<int,N,M> x)\n")
8534
0
SLANG_RAW("{ return x; }\n")
8535
0
SLANG_RAW("\n")
8536
0
SLANG_RAW("/// Reinterpret bits of double as a uint.\n")
8537
0
SLANG_RAW("/// @category conversion\n")
8538
0
SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader5)\n")
8539
0
SLANG_RAW("[__readNone]\n")
8540
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_4_0)]\n")
8541
0
SLANG_RAW("void asuint(double value, out uint lowbits, out uint highbits)\n")
8542
0
SLANG_RAW("{\n")
8543
0
SLANG_RAW("    __target_switch\n")
8544
0
SLANG_RAW("    {\n")
8545
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8546
0
SLANG_RAW("    case glsl: __intrinsic_asm \"{ uvec2 v = unpackDouble2x32($0); $1 = v.x; $2 = v.y; }\";\n")
8547
0
SLANG_RAW("    case cpp:\n")
8548
0
SLANG_RAW("    case cuda:\n")
8549
0
SLANG_RAW("        __intrinsic_asm \"$P_asuint($0, $1, $2)\";\n")
8550
0
SLANG_RAW("    case spirv:\n")
8551
0
SLANG_RAW("        let uv = spirv_asm\n")
8552
0
SLANG_RAW("        {\n")
8553
0
SLANG_RAW("            result : $$uint2 = OpBitcast $value;\n")
8554
0
SLANG_RAW("        };\n")
8555
0
SLANG_RAW("        lowbits = uv.x;\n")
8556
0
SLANG_RAW("        highbits = uv.y;\n")
8557
0
SLANG_RAW("        return;\n")
8558
0
SLANG_RAW("    }\n")
8559
0
SLANG_RAW("}\n")
8560
0
SLANG_RAW("\n")
8561
0
SLANG_RAW("// Reinterpret bits as a uint.\n")
8562
0
SLANG_RAW("\n")
8563
0
SLANG_RAW("[__readNone]\n")
8564
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8565
0
SLANG_RAW("uint asuint(float x)\n")
8566
0
SLANG_RAW("{\n")
8567
0
SLANG_RAW("    __target_switch\n")
8568
0
SLANG_RAW("    {\n")
8569
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asuint($0)\";\n")
8570
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asuint($0)\";\n")
8571
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floatBitsToUint\";\n")
8572
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8573
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8574
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8575
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8576
0
SLANG_RAW("        OpBitcast $$uint result $x\n")
8577
0
SLANG_RAW("    };\n")
8578
0
SLANG_RAW("    }\n")
8579
0
SLANG_RAW("}\n")
8580
0
SLANG_RAW("\n")
8581
0
SLANG_RAW("[__readNone]\n")
8582
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8583
0
SLANG_RAW("uint asuint(int x)\n")
8584
0
SLANG_RAW("{\n")
8585
0
SLANG_RAW("    __target_switch\n")
8586
0
SLANG_RAW("    {\n")
8587
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_asuint($0)\";\n")
8588
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_asuint($0)\";\n")
8589
0
SLANG_RAW("    case glsl: __intrinsic_asm \"uint($0)\";\n")
8590
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8591
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8592
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8593
0
SLANG_RAW("        OpBitcast $$uint result $x\n")
8594
0
SLANG_RAW("    };\n")
8595
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8596
0
SLANG_RAW("    }\n")
8597
0
SLANG_RAW("}\n")
8598
0
SLANG_RAW("\n")
8599
0
SLANG_RAW("__generic<let N : int>\n")
8600
0
SLANG_RAW("[__readNone]\n")
8601
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8602
0
SLANG_RAW("vector<uint,N> asuint(vector<float,N> x)\n")
8603
0
SLANG_RAW("{\n")
8604
0
SLANG_RAW("    __target_switch\n")
8605
0
SLANG_RAW("    {\n")
8606
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floatBitsToUint\";\n")
8607
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8608
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8609
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8610
0
SLANG_RAW("        OpBitcast $$vector<uint,N> result $x\n")
8611
0
SLANG_RAW("    };\n")
8612
0
SLANG_RAW("    default:\n")
8613
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, asuint, x);\n")
8614
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8615
0
SLANG_RAW("    }\n")
8616
0
SLANG_RAW("}\n")
8617
0
SLANG_RAW("\n")
8618
0
SLANG_RAW("__generic<let N : int>\n")
8619
0
SLANG_RAW("[__readNone]\n")
8620
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_4_0)]\n")
8621
0
SLANG_RAW("vector<uint, N> asuint(vector<int, N> x)\n")
8622
0
SLANG_RAW("{\n")
8623
0
SLANG_RAW("    if(N == 1)\n")
8624
0
SLANG_RAW("        return vector<uint, N>(asuint(x[0]));\n")
8625
0
SLANG_RAW("    __target_switch\n")
8626
0
SLANG_RAW("    {\n")
8627
0
SLANG_RAW("    case glsl: __intrinsic_asm \"uvec$N0($0)\";\n")
8628
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8629
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8630
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8631
0
SLANG_RAW("        OpBitcast $$vector<uint, N> result $x\n")
8632
0
SLANG_RAW("    };\n")
8633
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<$TR>($0)\";\n")
8634
0
SLANG_RAW("    default:\n")
8635
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, asuint, x);\n")
8636
0
SLANG_RAW("    }\n")
8637
0
SLANG_RAW("}\n")
8638
0
SLANG_RAW("\n")
8639
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8640
0
SLANG_RAW("[__readNone]\n")
8641
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_4_0)]\n")
8642
0
SLANG_RAW("matrix<uint,N,M> asuint(matrix<float,N,M> x)\n")
8643
0
SLANG_RAW("{\n")
8644
0
SLANG_RAW("    __target_switch\n")
8645
0
SLANG_RAW("    {\n")
8646
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8647
0
SLANG_RAW("    default:\n")
8648
0
SLANG_RAW("        MATRIX_MAP_UNARY(uint, N, M, asuint, x);\n")
8649
0
SLANG_RAW("    }\n")
8650
0
SLANG_RAW("}\n")
8651
0
SLANG_RAW("\n")
8652
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8653
0
SLANG_RAW("[__readNone]\n")
8654
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_4_0)]\n")
8655
0
SLANG_RAW("matrix<uint, N, M> asuint(matrix<int, N, M> x)\n")
8656
0
SLANG_RAW("{\n")
8657
0
SLANG_RAW("    __target_switch\n")
8658
0
SLANG_RAW("    {\n")
8659
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint\";\n")
8660
0
SLANG_RAW("    default:\n")
8661
0
SLANG_RAW("        MATRIX_MAP_UNARY(uint, N, M, asuint, x);\n")
8662
0
SLANG_RAW("    }\n")
8663
0
SLANG_RAW("}\n")
8664
0
SLANG_RAW("\n")
8665
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8666
0
SLANG_RAW("[__readNone]\n")
8667
0
SLANG_RAW("uint asuint(uint x)\n")
8668
0
SLANG_RAW("{ return x; }\n")
8669
0
SLANG_RAW("\n")
8670
0
SLANG_RAW("__generic<let N : int>\n")
8671
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8672
0
SLANG_RAW("[__readNone]\n")
8673
0
SLANG_RAW("vector<uint,N> asuint(vector<uint,N> x)\n")
8674
0
SLANG_RAW("{ return x; }\n")
8675
0
SLANG_RAW("\n")
8676
0
SLANG_RAW("__generic<let N : int, let M : int>\n")
8677
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8678
0
SLANG_RAW("[__readNone]\n")
8679
0
SLANG_RAW("matrix<uint,N,M> asuint(matrix<uint,N,M> x)\n")
8680
0
SLANG_RAW("{ return x; }\n")
8681
0
SLANG_RAW("\n")
8682
0
SLANG_RAW("\n")
8683
0
SLANG_RAW("// 16-bit bitcast ops (HLSL SM 6.2)\n")
8684
0
SLANG_RAW("//\n")
8685
0
SLANG_RAW("// TODO: We need to map these to GLSL/SPIR-V\n")
8686
0
SLANG_RAW("// operations that don't require an intermediate\n")
8687
0
SLANG_RAW("// conversion to fp32.\n")
8688
0
SLANG_RAW("\n")
8689
0
SLANG_RAW("// Identity cases:\n")
8690
0
SLANG_RAW("\n")
8691
0
SLANG_RAW("/// Reinterpret bits as a float16 (HLSL SM 6.2).\n")
8692
0
SLANG_RAW("/// @category conversion\n")
8693
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] float16_t asfloat16(float16_t value) { return value; }\n")
8694
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] vector<float16_t,N> asfloat16<let N : int>(vector<float16_t,N> value) { return value; }\n")
8695
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] matrix<float16_t,R,C> asfloat16<let R : int, let C : int>(matrix<float16_t,R,C> value) { return value; }\n")
8696
0
SLANG_RAW("\n")
8697
0
SLANG_RAW("/// Reinterpret bits as a int16_t (HLSL SM 6.2).\n")
8698
0
SLANG_RAW("/// @category conversion\n")
8699
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] int16_t asint16(int16_t value) { return value; }\n")
8700
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] vector<int16_t,N> asint16<let N : int>(vector<int16_t,N> value) { return value; }\n")
8701
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] matrix<int16_t,R,C> asint16<let R : int, let C : int>(matrix<int16_t,R,C> value) { return value; }\n")
8702
0
SLANG_RAW("\n")
8703
0
SLANG_RAW("/// Reinterpret bits as a uint16_t (HLSL SM 6.2).\n")
8704
0
SLANG_RAW("/// @category conversion\n")
8705
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] uint16_t asuint16(uint16_t value) { return value; }\n")
8706
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] vector<uint16_t,N> asuint16<let N : int>(vector<uint16_t,N> value) { return value; }\n")
8707
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] matrix<uint16_t,R,C> asuint16<let R : int, let C : int>(matrix<uint16_t,R,C> value) { return value; }\n")
8708
0
SLANG_RAW("\n")
8709
0
SLANG_RAW("// Signed<->unsigned cases:\n")
8710
0
SLANG_RAW("\n")
8711
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] int16_t asint16(uint16_t value) { return value; }\n")
8712
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] vector<int16_t,N> asint16<let N : int>(vector<uint16_t,N> value) { return value; }\n")
8713
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] matrix<int16_t,R,C> asint16<let R : int, let C : int>(matrix<uint16_t,R,C> value) { return value; }\n")
8714
0
SLANG_RAW("\n")
8715
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] uint16_t asuint16(int16_t value) { return value; }\n")
8716
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] vector<uint16_t,N> asuint16<let N : int>(vector<int16_t,N> value) { return value; }\n")
8717
0
SLANG_RAW("[__unsafeForceInlineEarly][__readNone] matrix<uint16_t,R,C> asuint16<let R : int, let C : int>(matrix<int16_t,R,C> value) { return value; }\n")
8718
0
SLANG_RAW("\n")
8719
0
SLANG_RAW("// Float->unsigned cases:\n")
8720
0
SLANG_RAW("\n")
8721
0
SLANG_RAW("[__readNone]\n")
8722
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8723
0
SLANG_RAW("uint16_t asuint16(float16_t value)\n")
8724
0
SLANG_RAW("{\n")
8725
0
SLANG_RAW("    __target_switch\n")
8726
0
SLANG_RAW("    {\n")
8727
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half_as_ushort\";\n")
8728
0
SLANG_RAW("    case glsl: __intrinsic_asm \"uint16_t(packHalf2x16(vec2($0, 0.0)))\";\n")
8729
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint16\";\n")
8730
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8731
0
SLANG_RAW("        OpBitcast $$uint16_t result $value\n")
8732
0
SLANG_RAW("    };\n")
8733
0
SLANG_RAW("    }\n")
8734
0
SLANG_RAW("}\n")
8735
0
SLANG_RAW("\n")
8736
0
SLANG_RAW("[__readNone]\n")
8737
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8738
0
SLANG_RAW("vector<uint16_t,N> asuint16<let N : int>(vector<float16_t,N> value)\n")
8739
0
SLANG_RAW("{\n")
8740
0
SLANG_RAW("    __target_switch\n")
8741
0
SLANG_RAW("    {\n")
8742
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asuint16\";\n")
8743
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8744
0
SLANG_RAW("        result:$$vector<uint16_t,N> = OpBitcast $value\n")
8745
0
SLANG_RAW("    };\n")
8746
0
SLANG_RAW("    default:\n")
8747
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint16_t, N, asuint16, value);\n")
8748
0
SLANG_RAW("    }\n")
8749
0
SLANG_RAW("}\n")
8750
0
SLANG_RAW("\n")
8751
0
SLANG_RAW("[__readNone]\n")
8752
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8753
0
SLANG_RAW("matrix<uint16_t,R,C> asuint16<let R : int, let C : int>(matrix<float16_t,R,C> value)\n")
8754
0
SLANG_RAW("{ MATRIX_MAP_UNARY(uint16_t, R, C, asuint16, value); }\n")
8755
0
SLANG_RAW("\n")
8756
0
SLANG_RAW("// Unsigned->float cases:\n")
8757
0
SLANG_RAW("\n")
8758
0
SLANG_RAW("[__readNone]\n")
8759
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
8760
0
SLANG_RAW("float16_t asfloat16(uint16_t value)\n")
8761
0
SLANG_RAW("{\n")
8762
0
SLANG_RAW("    __target_switch\n")
8763
0
SLANG_RAW("    {\n")
8764
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__ushort_as_half\";\n")
8765
0
SLANG_RAW("    case glsl: __intrinsic_asm \"float16_t(unpackHalf2x16($0).x)\";\n")
8766
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat16\";\n")
8767
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8768
0
SLANG_RAW("        OpBitcast $$float16_t result $value\n")
8769
0
SLANG_RAW("    };\n")
8770
0
SLANG_RAW("    }\n")
8771
0
SLANG_RAW("}\n")
8772
0
SLANG_RAW("\n")
8773
0
SLANG_RAW("[__readNone]\n")
8774
0
SLANG_RAW("vector<float16_t,N> asfloat16<let N : int>(vector<uint16_t,N> value)\n")
8775
0
SLANG_RAW("{\n")
8776
0
SLANG_RAW("    __target_switch\n")
8777
0
SLANG_RAW("    {\n")
8778
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat16\";\n")
8779
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8780
0
SLANG_RAW("        result:$$vector<float16_t,N> = OpBitcast $value\n")
8781
0
SLANG_RAW("    };\n")
8782
0
SLANG_RAW("    default:\n")
8783
0
SLANG_RAW("        VECTOR_MAP_UNARY(float16_t, N, asfloat16, value);\n")
8784
0
SLANG_RAW("    }\n")
8785
0
SLANG_RAW("}\n")
8786
0
SLANG_RAW("\n")
8787
0
SLANG_RAW("[__readNone]\n")
8788
0
SLANG_RAW("matrix<float16_t,R,C> asfloat16<let R : int, let C : int>(matrix<uint16_t,R,C> value)\n")
8789
0
SLANG_RAW("{ MATRIX_MAP_UNARY(float16_t, R, C, asfloat16, value); }\n")
8790
0
SLANG_RAW("\n")
8791
0
SLANG_RAW("// Float<->signed cases:\n")
8792
0
SLANG_RAW("\n")
8793
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8794
0
SLANG_RAW("[__readNone]\n")
8795
0
SLANG_RAW("int16_t asint16(float16_t value)\n")
8796
0
SLANG_RAW("{\n")
8797
0
SLANG_RAW("    __target_switch\n")
8798
0
SLANG_RAW("    {\n")
8799
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half_as_short\";\n")
8800
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint16\";\n")
8801
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8802
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8803
0
SLANG_RAW("        OpBitcast $$int16_t result $value\n")
8804
0
SLANG_RAW("    };\n")
8805
0
SLANG_RAW("    default: return asuint16(value);\n")
8806
0
SLANG_RAW("    }\n")
8807
0
SLANG_RAW("}\n")
8808
0
SLANG_RAW("\n")
8809
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8810
0
SLANG_RAW("[__readNone]\n")
8811
0
SLANG_RAW("vector<int16_t,N> asint16<let N : int>(vector<float16_t,N> value)\n")
8812
0
SLANG_RAW("{\n")
8813
0
SLANG_RAW("    __target_switch\n")
8814
0
SLANG_RAW("    {\n")
8815
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint16\";\n")
8816
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8817
0
SLANG_RAW("    default: return asuint16(value);\n")
8818
0
SLANG_RAW("    }\n")
8819
0
SLANG_RAW("}\n")
8820
0
SLANG_RAW("\n")
8821
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8822
0
SLANG_RAW("[__readNone]\n")
8823
0
SLANG_RAW("matrix<int16_t,R,C> asint16<let R : int, let C : int>(matrix<float16_t,R,C> value)\n")
8824
0
SLANG_RAW("{\n")
8825
0
SLANG_RAW("    __target_switch\n")
8826
0
SLANG_RAW("    {\n")
8827
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asint16\";\n")
8828
0
SLANG_RAW("    default: return asuint16(value);\n")
8829
0
SLANG_RAW("    }\n")
8830
0
SLANG_RAW("}\n")
8831
0
SLANG_RAW("\n")
8832
0
SLANG_RAW("[__readNone]\n")
8833
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8834
0
SLANG_RAW("float16_t asfloat16(int16_t value)\n")
8835
0
SLANG_RAW("{\n")
8836
0
SLANG_RAW("    __target_switch\n")
8837
0
SLANG_RAW("    {\n")
8838
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__short_as_half\";\n")
8839
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat16\";\n")
8840
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8841
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8842
0
SLANG_RAW("        OpBitcast $$float16_t result $value\n")
8843
0
SLANG_RAW("    };\n")
8844
0
SLANG_RAW("    default: return asfloat16(asuint16(value));\n")
8845
0
SLANG_RAW("    }\n")
8846
0
SLANG_RAW("}\n")
8847
0
SLANG_RAW("\n")
8848
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8849
0
SLANG_RAW("[__readNone]\n")
8850
0
SLANG_RAW("vector<float16_t,N> asfloat16<let N : int>(vector<int16_t,N> value)\n")
8851
0
SLANG_RAW("{\n")
8852
0
SLANG_RAW("    __target_switch\n")
8853
0
SLANG_RAW("    {\n")
8854
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat16\";\n")
8855
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<$TR>($0)\";\n")
8856
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8857
0
SLANG_RAW("        OpBitcast $$vector<float16_t,N> result $value\n")
8858
0
SLANG_RAW("    };\n")
8859
0
SLANG_RAW("    default: return asfloat16(asuint16(value));\n")
8860
0
SLANG_RAW("    }\n")
8861
0
SLANG_RAW("}\n")
8862
0
SLANG_RAW("\n")
8863
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
8864
0
SLANG_RAW("[__readNone]\n")
8865
0
SLANG_RAW("matrix<float16_t,R,C> asfloat16<let R : int, let C : int>(matrix<int16_t,R,C> value)\n")
8866
0
SLANG_RAW("{\n")
8867
0
SLANG_RAW("    __target_switch\n")
8868
0
SLANG_RAW("    {\n")
8869
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"asfloat16\";\n")
8870
0
SLANG_RAW("    default: return asfloat16(asuint16(value));\n")
8871
0
SLANG_RAW("    }\n")
8872
0
SLANG_RAW("}\n")
8873
0
SLANG_RAW("\n")
8874
0
SLANG_RAW("/// Arc tangent. Returns the angle whose tangent is the specified number.\n")
8875
0
SLANG_RAW("/// @param x The tangent value.\n")
8876
0
SLANG_RAW("/// @return The angle in radians, in the range of [-pi/2, pi/2].\n")
8877
0
SLANG_RAW("/// @category math\n")
8878
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
8879
0
SLANG_RAW("[__readNone]\n")
8880
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8881
0
SLANG_RAW("T atan(T x)\n")
8882
0
SLANG_RAW("{\n")
8883
0
SLANG_RAW("    __target_switch\n")
8884
0
SLANG_RAW("    {\n")
8885
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_atan($0)\";\n")
8886
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_atan($0)\";\n")
8887
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atan\";\n")
8888
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan\";\n")
8889
0
SLANG_RAW("    case metal: __intrinsic_asm \"atan\";\n")
8890
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8891
0
SLANG_RAW("        OpExtInst $$T result glsl450 Atan $x\n")
8892
0
SLANG_RAW("    };\n")
8893
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atan\";\n")
8894
0
SLANG_RAW("    }\n")
8895
0
SLANG_RAW("}\n")
8896
0
SLANG_RAW("\n")
8897
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
8898
0
SLANG_RAW("[__readNone]\n")
8899
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8900
0
SLANG_RAW("vector<T, N> atan(vector<T, N> x)\n")
8901
0
SLANG_RAW("{\n")
8902
0
SLANG_RAW("    __target_switch\n")
8903
0
SLANG_RAW("    {\n")
8904
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atan\";\n")
8905
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan\";\n")
8906
0
SLANG_RAW("    case metal: __intrinsic_asm \"atan\";\n")
8907
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8908
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Atan $x\n")
8909
0
SLANG_RAW("    };\n")
8910
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atan\";\n")
8911
0
SLANG_RAW("    default:\n")
8912
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, atan, x);\n")
8913
0
SLANG_RAW("    }\n")
8914
0
SLANG_RAW("}\n")
8915
0
SLANG_RAW("\n")
8916
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
8917
0
SLANG_RAW("[__readNone]\n")
8918
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8919
0
SLANG_RAW("matrix<T, N, M> atan(matrix<T, N, M> x)\n")
8920
0
SLANG_RAW("{\n")
8921
0
SLANG_RAW("    __target_switch\n")
8922
0
SLANG_RAW("    {\n")
8923
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan\";\n")
8924
0
SLANG_RAW("    default:\n")
8925
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, atan, x);\n")
8926
0
SLANG_RAW("    }\n")
8927
0
SLANG_RAW("}\n")
8928
0
SLANG_RAW("\n")
8929
0
SLANG_RAW("/// Arc tangent of y/x. Returns the angle whose tangent is the quotient of two specified numbers.\n")
8930
0
SLANG_RAW("/// @param y The numerator.\n")
8931
0
SLANG_RAW("/// @param x The denominator.\n")
8932
0
SLANG_RAW("/// @return The angle in radians, in the range of [-pi, pi].\n")
8933
0
SLANG_RAW("/// @category math\n")
8934
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
8935
0
SLANG_RAW("[__readNone]\n")
8936
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8937
0
SLANG_RAW("T atan2(T y, T x)\n")
8938
0
SLANG_RAW("{\n")
8939
0
SLANG_RAW("    __target_switch\n")
8940
0
SLANG_RAW("    {\n")
8941
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_atan2($0, $1)\";\n")
8942
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_atan2($0, $1)\";\n")
8943
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atan($0,$1)\";\n")
8944
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan2\";\n")
8945
0
SLANG_RAW("    case metal: __intrinsic_asm \"atan2\";\n")
8946
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8947
0
SLANG_RAW("        OpExtInst $$T result glsl450 Atan2 $y $x\n")
8948
0
SLANG_RAW("    };\n")
8949
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atan2\";\n")
8950
0
SLANG_RAW("    }\n")
8951
0
SLANG_RAW("}\n")
8952
0
SLANG_RAW("\n")
8953
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
8954
0
SLANG_RAW("[__readNone]\n")
8955
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8956
0
SLANG_RAW("vector<T, N> atan2(vector<T, N> y, vector<T, N> x)\n")
8957
0
SLANG_RAW("{\n")
8958
0
SLANG_RAW("    __target_switch\n")
8959
0
SLANG_RAW("    {\n")
8960
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atan($0,$1)\";\n")
8961
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan2\";\n")
8962
0
SLANG_RAW("    case metal: __intrinsic_asm \"atan2\";\n")
8963
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
8964
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Atan2 $y $x\n")
8965
0
SLANG_RAW("    };\n")
8966
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atan2\";\n")
8967
0
SLANG_RAW("    default:\n")
8968
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, atan2, y, x);\n")
8969
0
SLANG_RAW("    }\n")
8970
0
SLANG_RAW("}\n")
8971
0
SLANG_RAW("\n")
8972
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
8973
0
SLANG_RAW("[__readNone]\n")
8974
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8975
0
SLANG_RAW("matrix<T,N,M> atan2(matrix<T,N,M> y, matrix<T,N,M> x)\n")
8976
0
SLANG_RAW("{\n")
8977
0
SLANG_RAW("    __target_switch\n")
8978
0
SLANG_RAW("    {\n")
8979
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atan2\";\n")
8980
0
SLANG_RAW("    default:\n")
8981
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, atan2, y, x);\n")
8982
0
SLANG_RAW("    }\n")
8983
0
SLANG_RAW("}\n")
8984
0
SLANG_RAW("\n")
8985
0
SLANG_RAW("/// Hyperbolic arc tangent. Returns the hyperbolic arc tangent of the specified value.\n")
8986
0
SLANG_RAW("/// @param x The value.\n")
8987
0
SLANG_RAW("/// @return The hyperbolic arc tangent of the specified value.\n")
8988
0
SLANG_RAW("/// @category math\n")
8989
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
8990
0
SLANG_RAW("[__readNone]\n")
8991
0
SLANG_RAW("[ForceInline]\n")
8992
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
8993
0
SLANG_RAW("T atanh(T x)\n")
8994
0
SLANG_RAW("{\n")
8995
0
SLANG_RAW("    __target_switch\n")
8996
0
SLANG_RAW("    {\n")
8997
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_atanh($0)\";\n")
8998
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_atanh($0)\";\n")
8999
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atanh\";\n")
9000
0
SLANG_RAW("    case metal: __intrinsic_asm \"atanh\";\n")
9001
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9002
0
SLANG_RAW("        OpExtInst $$T result glsl450 Atanh $x\n")
9003
0
SLANG_RAW("    };\n")
9004
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atanh\";\n")
9005
0
SLANG_RAW("    default:\n")
9006
0
SLANG_RAW("        return T(0.5) * log((T(1) + x) / (T(1) - x));\n")
9007
0
SLANG_RAW("    }\n")
9008
0
SLANG_RAW("}\n")
9009
0
SLANG_RAW("\n")
9010
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N:int>\n")
9011
0
SLANG_RAW("[__readNone]\n")
9012
0
SLANG_RAW("[ForceInline]\n")
9013
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9014
0
SLANG_RAW("vector<T,N> atanh(vector<T,N> x)\n")
9015
0
SLANG_RAW("{\n")
9016
0
SLANG_RAW("    __target_switch\n")
9017
0
SLANG_RAW("    {\n")
9018
0
SLANG_RAW("    case glsl: __intrinsic_asm \"atanh\";\n")
9019
0
SLANG_RAW("    case metal: __intrinsic_asm \"atanh\";\n")
9020
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9021
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Atanh $x\n")
9022
0
SLANG_RAW("    };\n")
9023
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"atanh\";\n")
9024
0
SLANG_RAW("    default:\n")
9025
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, atanh, x);\n")
9026
0
SLANG_RAW("    }\n")
9027
0
SLANG_RAW("}\n")
9028
0
SLANG_RAW("\n")
9029
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9030
0
SLANG_RAW("[__readNone]\n")
9031
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9032
0
SLANG_RAW("matrix<T, N, M> atanh(matrix<T, N, M> x)\n")
9033
0
SLANG_RAW("{\n")
9034
0
SLANG_RAW("    __target_switch\n")
9035
0
SLANG_RAW("    {\n")
9036
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"atanh\";\n")
9037
0
SLANG_RAW("    default:\n")
9038
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, atanh, x);\n")
9039
0
SLANG_RAW("    }\n")
9040
0
SLANG_RAW("}\n")
9041
0
SLANG_RAW("\n")
9042
0
SLANG_RAW("/// Ceiling. Returns the smallest integer that is greater than or equal to the specified value.\n")
9043
0
SLANG_RAW("/// @param x The value.\n")
9044
0
SLANG_RAW("/// @return The smallest integer that is greater than or equal to the specified value.\n")
9045
0
SLANG_RAW("/// @category math\n")
9046
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9047
0
SLANG_RAW("[__readNone]\n")
9048
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9049
0
SLANG_RAW("T ceil(T x)\n")
9050
0
SLANG_RAW("{\n")
9051
0
SLANG_RAW("    __target_switch\n")
9052
0
SLANG_RAW("    {\n")
9053
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_ceil($0)\";\n")
9054
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_ceil($0)\";\n")
9055
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ceil\";\n")
9056
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ceil\";\n")
9057
0
SLANG_RAW("    case metal: __intrinsic_asm \"ceil\";\n")
9058
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9059
0
SLANG_RAW("        OpExtInst $$T result glsl450 Ceil $x\n")
9060
0
SLANG_RAW("    };\n")
9061
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"ceil\";\n")
9062
0
SLANG_RAW("    }\n")
9063
0
SLANG_RAW("}\n")
9064
0
SLANG_RAW("\n")
9065
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9066
0
SLANG_RAW("[__readNone]\n")
9067
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9068
0
SLANG_RAW("vector<T, N> ceil(vector<T, N> x)\n")
9069
0
SLANG_RAW("{\n")
9070
0
SLANG_RAW("    __target_switch\n")
9071
0
SLANG_RAW("    {\n")
9072
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ceil\";\n")
9073
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ceil\";\n")
9074
0
SLANG_RAW("    case metal: __intrinsic_asm \"ceil\";\n")
9075
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9076
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Ceil $x\n")
9077
0
SLANG_RAW("    };\n")
9078
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"ceil\";\n")
9079
0
SLANG_RAW("    default:\n")
9080
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, ceil, x);\n")
9081
0
SLANG_RAW("    }\n")
9082
0
SLANG_RAW("}\n")
9083
0
SLANG_RAW("\n")
9084
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9085
0
SLANG_RAW("[__readNone]\n")
9086
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9087
0
SLANG_RAW("matrix<T, N, M> ceil(matrix<T, N, M> x)\n")
9088
0
SLANG_RAW("{\n")
9089
0
SLANG_RAW("    __target_switch\n")
9090
0
SLANG_RAW("    {\n")
9091
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ceil\";\n")
9092
0
SLANG_RAW("    default:\n")
9093
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, ceil, x);\n")
9094
0
SLANG_RAW("    }\n")
9095
0
SLANG_RAW("}\n")
9096
0
SLANG_RAW("\n")
9097
0
SLANG_RAW("/// Copy-sign. Returns a value whose magnitude is from one operand and whose sign is from another operand.\n")
9098
0
SLANG_RAW("/// @param x The value to use as the magnitude.\n")
9099
0
SLANG_RAW("/// @param y The value to use as the sign.\n")
9100
0
SLANG_RAW("/// @return A value whose magnitude is from `x` and whose sign is from `y`.\n")
9101
0
SLANG_RAW("/// @category math\n")
9102
0
SLANG_RAW("__generic<let N: int>\n")
9103
0
SLANG_RAW("[__readNone]\n")
9104
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
9105
0
SLANG_RAW("vector<half,N> copysign_half(vector<half,N> x, vector<half,N> y)\n")
9106
0
SLANG_RAW("{\n")
9107
0
SLANG_RAW("    let ux = reinterpret<vector<uint16_t,N>>(x);\n")
9108
0
SLANG_RAW("    let uy = reinterpret<vector<uint16_t,N>>(y);\n")
9109
0
SLANG_RAW("    vector<uint16_t,N> signY = (uy & (uint16_t(1) << uint16_t(15)));\n")
9110
0
SLANG_RAW("    vector<uint16_t,N> newX = (ux & ((uint16_t(1) << uint16_t(15)) - uint16_t(1))) + signY;\n")
9111
0
SLANG_RAW("    return reinterpret<vector<half,N>>(newX);\n")
9112
0
SLANG_RAW("}\n")
9113
0
SLANG_RAW("\n")
9114
0
SLANG_RAW("/// Copy-sign. Returns a value whose magnitude is from one operand and whose sign is from another operand.\n")
9115
0
SLANG_RAW("/// @param x The value to use as the magnitude.\n")
9116
0
SLANG_RAW("/// @param y The value to use as the sign.\n")
9117
0
SLANG_RAW("/// @return A value whose magnitude is from `x` and whose sign is from `y`.\n")
9118
0
SLANG_RAW("/// @category math\n")
9119
0
SLANG_RAW("__generic<let N: int>\n")
9120
0
SLANG_RAW("[__readNone]\n")
9121
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
9122
0
SLANG_RAW("vector<float,N> copysign_float(vector<float,N> x, vector<float,N> y)\n")
9123
0
SLANG_RAW("{\n")
9124
0
SLANG_RAW("    let ux = reinterpret<vector<uint32_t,N>>(x);\n")
9125
0
SLANG_RAW("    let uy = reinterpret<vector<uint32_t,N>>(y);\n")
9126
0
SLANG_RAW("    vector<uint32_t,N> signY = (uy & (uint32_t(1) << uint32_t(31)));\n")
9127
0
SLANG_RAW("    vector<uint32_t,N> newX = (ux & ((uint32_t(1) << uint32_t(31)) - uint32_t(1))) + signY;\n")
9128
0
SLANG_RAW("    return reinterpret<vector<float,N>>(newX);\n")
9129
0
SLANG_RAW("}\n")
9130
0
SLANG_RAW("\n")
9131
0
SLANG_RAW("/// Copy-sign. Returns a value whose magnitude is from one operand and whose sign is from another operand.\n")
9132
0
SLANG_RAW("/// @param x The value to use as the magnitude.\n")
9133
0
SLANG_RAW("/// @param y The value to use as the sign.\n")
9134
0
SLANG_RAW("/// @return A value whose magnitude is from `x` and whose sign is from `y`.\n")
9135
0
SLANG_RAW("/// @category math\n")
9136
0
SLANG_RAW("__generic<let N: int>\n")
9137
0
SLANG_RAW("[__readNone]\n")
9138
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
9139
0
SLANG_RAW("vector<double,N> copysign_double(vector<double,N> x, vector<double,N> y)\n")
9140
0
SLANG_RAW("{\n")
9141
0
SLANG_RAW("    let ux = reinterpret<vector<uint64_t,N>>(x);\n")
9142
0
SLANG_RAW("    let uy = reinterpret<vector<uint64_t,N>>(y);\n")
9143
0
SLANG_RAW("    vector<uint64_t,N> signY = (uy & (uint64_t(1) << uint64_t(63)));\n")
9144
0
SLANG_RAW("    vector<uint64_t,N> newX = (ux & ((uint64_t(1) << uint64_t(63)) - uint64_t(1))) + signY;\n")
9145
0
SLANG_RAW("    return reinterpret<vector<double,N>>(newX);\n")
9146
0
SLANG_RAW("}\n")
9147
0
SLANG_RAW("\n")
9148
0
SLANG_RAW("__generic<T:__BuiltinFloatingPointType, U:__BuiltinFloatingPointType, let N : int>\n")
9149
0
SLANG_RAW("__intrinsic_op(")
9150
0
SLANG_SPLICE(kIROp_FloatCast
9151
0
)
9152
0
SLANG_RAW(")\n")
9153
0
SLANG_RAW("vector<T,N> __real_cast(vector<U,N> val);\n")
9154
0
SLANG_RAW("\n")
9155
0
SLANG_RAW("/// Copy-sign. Returns a value whose magnitude is from one operand and whose sign is from another operand.\n")
9156
0
SLANG_RAW("/// @param x The value to use as the magnitude.\n")
9157
0
SLANG_RAW("/// @param y The value to use as the sign.\n")
9158
0
SLANG_RAW("/// @return A value whose magnitude is from x and whose sign is from y.\n")
9159
0
SLANG_RAW("/// @category math\n")
9160
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
9161
0
SLANG_RAW("[__readNone]\n")
9162
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
9163
0
SLANG_RAW("vector<T,N> copysign(vector<T,N> x, vector<T,N> y)\n")
9164
0
SLANG_RAW("{\n")
9165
0
SLANG_RAW("    __target_switch\n")
9166
0
SLANG_RAW("    {\n")
9167
0
SLANG_RAW("    case metal: __intrinsic_asm \"copysign\";\n")
9168
0
SLANG_RAW("    default:\n")
9169
0
SLANG_RAW("    {\n")
9170
0
SLANG_RAW("        // sign of -0.0 needs to be respected.\n")
9171
0
SLANG_RAW("        if (T is half)\n")
9172
0
SLANG_RAW("            return __real_cast<T>(copysign_half(\n")
9173
0
SLANG_RAW("                    __real_cast<half>(x),\n")
9174
0
SLANG_RAW("                    __real_cast<half>(y)));\n")
9175
0
SLANG_RAW("        if (T is float)\n")
9176
0
SLANG_RAW("            return __real_cast<T>(copysign_float(\n")
9177
0
SLANG_RAW("                    __real_cast<float>(x),\n")
9178
0
SLANG_RAW("                    __real_cast<float>(y)));\n")
9179
0
SLANG_RAW("        return __real_cast<T>(copysign_double(\n")
9180
0
SLANG_RAW("                __real_cast<double>(x),\n")
9181
0
SLANG_RAW("                __real_cast<double>(y)));\n")
9182
0
SLANG_RAW("    }\n")
9183
0
SLANG_RAW("    }\n")
9184
0
SLANG_RAW("}\n")
9185
0
SLANG_RAW("\n")
9186
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9187
0
SLANG_RAW("[__readNone]\n")
9188
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
9189
0
SLANG_RAW("T copysign(T x, T y)\n")
9190
0
SLANG_RAW("{\n")
9191
0
SLANG_RAW("    __target_switch\n")
9192
0
SLANG_RAW("    {\n")
9193
0
SLANG_RAW("    case metal: __intrinsic_asm \"copysign\";\n")
9194
0
SLANG_RAW("    default:\n")
9195
0
SLANG_RAW("        return copysign(vector<T,1>(x), vector<T,1>(y))[0];\n")
9196
0
SLANG_RAW("    }\n")
9197
0
SLANG_RAW("}\n")
9198
0
SLANG_RAW("\n")
9199
0
SLANG_RAW("\n")
9200
0
SLANG_RAW("// Check access status to tiled resource\n")
9201
0
SLANG_RAW("[ForceInline]\n")
9202
0
SLANG_RAW("[require(hlsl_spirv, sm_5_0)]\n")
9203
0
SLANG_RAW("bool CheckAccessFullyMapped(uint status)\n")
9204
0
SLANG_RAW("{\n")
9205
0
SLANG_RAW("    __target_switch\n")
9206
0
SLANG_RAW("    {\n")
9207
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"CheckAccessFullyMapped\";\n")
9208
0
SLANG_RAW("    case spirv:\n")
9209
0
SLANG_RAW("        return spirv_asm\n")
9210
0
SLANG_RAW("        {\n")
9211
0
SLANG_RAW("            OpCapability SparseResidency;\n")
9212
0
SLANG_RAW("            result:$$bool = OpImageSparseTexelsResident $status;\n")
9213
0
SLANG_RAW("        };\n")
9214
0
SLANG_RAW("    }\n")
9215
0
SLANG_RAW("}\n")
9216
0
SLANG_RAW("\n")
9217
0
SLANG_RAW("/// Clamp. Returns the specified value clamped to the specified minimum and maximum bounds.\n")
9218
0
SLANG_RAW("/// @param x The value to clamp.\n")
9219
0
SLANG_RAW("/// @param minBound The minimum bound.\n")
9220
0
SLANG_RAW("/// @param maxBound The maximum bound.\n")
9221
0
SLANG_RAW("/// @return The clamped value.\n")
9222
0
SLANG_RAW("/// @category math\n")
9223
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
9224
0
SLANG_RAW("[__readNone]\n")
9225
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9226
0
SLANG_RAW("T clamp(T x, T minBound, T maxBound)\n")
9227
0
SLANG_RAW("{\n")
9228
0
SLANG_RAW("    __target_switch\n")
9229
0
SLANG_RAW("    {\n")
9230
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9231
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clamp\";\n")
9232
0
SLANG_RAW("    case metal: __intrinsic_asm \"clamp\";\n")
9233
0
SLANG_RAW("    case spirv:\n")
9234
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
9235
0
SLANG_RAW("            return spirv_asm {\n")
9236
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 SClamp $x $minBound $maxBound\n")
9237
0
SLANG_RAW("            };\n")
9238
0
SLANG_RAW("        else\n")
9239
0
SLANG_RAW("            return spirv_asm {\n")
9240
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 UClamp $x $minBound $maxBound\n")
9241
0
SLANG_RAW("            };\n")
9242
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"clamp\";\n")
9243
0
SLANG_RAW("    default:\n")
9244
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9245
0
SLANG_RAW("    }\n")
9246
0
SLANG_RAW("}\n")
9247
0
SLANG_RAW("\n")
9248
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
9249
0
SLANG_RAW("[__readNone]\n")
9250
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9251
0
SLANG_RAW("vector<T, N> clamp(vector<T, N> x, vector<T, N> minBound, vector<T, N> maxBound)\n")
9252
0
SLANG_RAW("{\n")
9253
0
SLANG_RAW("    __target_switch\n")
9254
0
SLANG_RAW("    {\n")
9255
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9256
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clamp\";\n")
9257
0
SLANG_RAW("    case metal: __intrinsic_asm \"clamp\";\n")
9258
0
SLANG_RAW("    case spirv:\n")
9259
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
9260
0
SLANG_RAW("            return spirv_asm {\n")
9261
0
SLANG_RAW("                result:$$vector<T, N> = OpExtInst glsl450 SClamp $x $minBound $maxBound\n")
9262
0
SLANG_RAW("            };\n")
9263
0
SLANG_RAW("        else\n")
9264
0
SLANG_RAW("            return spirv_asm {\n")
9265
0
SLANG_RAW("                result:$$vector<T, N> = OpExtInst glsl450 UClamp $x $minBound $maxBound\n")
9266
0
SLANG_RAW("            };\n")
9267
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"clamp\";\n")
9268
0
SLANG_RAW("    default:\n")
9269
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9270
0
SLANG_RAW("    }\n")
9271
0
SLANG_RAW("}\n")
9272
0
SLANG_RAW("\n")
9273
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
9274
0
SLANG_RAW("[__readNone]\n")
9275
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9276
0
SLANG_RAW("matrix<T,N,M> clamp(matrix<T,N,M> x, matrix<T,N,M> minBound, matrix<T,N,M> maxBound)\n")
9277
0
SLANG_RAW("{\n")
9278
0
SLANG_RAW("    __target_switch\n")
9279
0
SLANG_RAW("    {\n")
9280
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9281
0
SLANG_RAW("    default:\n")
9282
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9283
0
SLANG_RAW("    }\n")
9284
0
SLANG_RAW("}\n")
9285
0
SLANG_RAW("\n")
9286
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9287
0
SLANG_RAW("[__readNone]\n")
9288
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9289
0
SLANG_RAW("T clamp(T x, T minBound, T maxBound)\n")
9290
0
SLANG_RAW("{\n")
9291
0
SLANG_RAW("    __target_switch\n")
9292
0
SLANG_RAW("    {\n")
9293
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9294
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clamp\";\n")
9295
0
SLANG_RAW("    case metal: __intrinsic_asm \"clamp\";\n")
9296
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9297
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 FClamp $x $minBound $maxBound\n")
9298
0
SLANG_RAW("    };\n")
9299
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"clamp\";\n")
9300
0
SLANG_RAW("    default:\n")
9301
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9302
0
SLANG_RAW("    }\n")
9303
0
SLANG_RAW("}\n")
9304
0
SLANG_RAW("\n")
9305
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9306
0
SLANG_RAW("[__readNone]\n")
9307
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9308
0
SLANG_RAW("vector<T, N> clamp(vector<T, N> x, vector<T, N> minBound, vector<T, N> maxBound)\n")
9309
0
SLANG_RAW("{\n")
9310
0
SLANG_RAW("    __target_switch\n")
9311
0
SLANG_RAW("    {\n")
9312
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9313
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clamp\";\n")
9314
0
SLANG_RAW("    case metal: __intrinsic_asm \"clamp\";\n")
9315
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9316
0
SLANG_RAW("        result:$$vector<T,N> = OpExtInst glsl450 FClamp $x $minBound $maxBound\n")
9317
0
SLANG_RAW("    };\n")
9318
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"clamp\";\n")
9319
0
SLANG_RAW("    default:\n")
9320
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9321
0
SLANG_RAW("    }\n")
9322
0
SLANG_RAW("}\n")
9323
0
SLANG_RAW("\n")
9324
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9325
0
SLANG_RAW("[__readNone]\n")
9326
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9327
0
SLANG_RAW("matrix<T,N,M> clamp(matrix<T,N,M> x, matrix<T,N,M> minBound, matrix<T,N,M> maxBound)\n")
9328
0
SLANG_RAW("{\n")
9329
0
SLANG_RAW("    __target_switch\n")
9330
0
SLANG_RAW("    {\n")
9331
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clamp\";\n")
9332
0
SLANG_RAW("    default:\n")
9333
0
SLANG_RAW("        return min(max(x, minBound), maxBound);\n")
9334
0
SLANG_RAW("    }\n")
9335
0
SLANG_RAW("}\n")
9336
0
SLANG_RAW("\n")
9337
0
SLANG_RAW("/// Clip (discard) fragment conditionally\n")
9338
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9339
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, fragment)]\n")
9340
0
SLANG_RAW("void clip(T x)\n")
9341
0
SLANG_RAW("{\n")
9342
0
SLANG_RAW("    __target_switch\n")
9343
0
SLANG_RAW("    {\n")
9344
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clip\";\n")
9345
0
SLANG_RAW("    default:\n")
9346
0
SLANG_RAW("        if(x < T(0)) discard;\n")
9347
0
SLANG_RAW("    }\n")
9348
0
SLANG_RAW("}\n")
9349
0
SLANG_RAW("\n")
9350
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9351
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, fragment)]\n")
9352
0
SLANG_RAW("void clip(vector<T,N> x)\n")
9353
0
SLANG_RAW("{\n")
9354
0
SLANG_RAW("    __target_switch\n")
9355
0
SLANG_RAW("    {\n")
9356
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clip\";\n")
9357
0
SLANG_RAW("    default:\n")
9358
0
SLANG_RAW("        if(any(x < T(0))) discard;\n")
9359
0
SLANG_RAW("    }\n")
9360
0
SLANG_RAW("}\n")
9361
0
SLANG_RAW("\n")
9362
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9363
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, fragment)]\n")
9364
0
SLANG_RAW("void clip(matrix<T,N,M> x)\n")
9365
0
SLANG_RAW("{\n")
9366
0
SLANG_RAW("    __target_switch\n")
9367
0
SLANG_RAW("    {\n")
9368
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"clip\";\n")
9369
0
SLANG_RAW("    default:\n")
9370
0
SLANG_RAW("        if(any(x < T(0))) discard;\n")
9371
0
SLANG_RAW("    }\n")
9372
0
SLANG_RAW("}\n")
9373
0
SLANG_RAW("\n")
9374
0
SLANG_RAW("/// Cosine. Returns the cosine of the specified angle.\n")
9375
0
SLANG_RAW("/// @param x The angle in radians.\n")
9376
0
SLANG_RAW("/// @return The cosine of the specified angle.\n")
9377
0
SLANG_RAW("/// @category math\n")
9378
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9379
0
SLANG_RAW("[__readNone]\n")
9380
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9381
0
SLANG_RAW("T cos(T x)\n")
9382
0
SLANG_RAW("{\n")
9383
0
SLANG_RAW("    __target_switch\n")
9384
0
SLANG_RAW("    {\n")
9385
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_cos($0)\";\n")
9386
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_cos($0)\";\n")
9387
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cos\";\n")
9388
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cos\";\n")
9389
0
SLANG_RAW("    case metal: __intrinsic_asm \"cos\";\n")
9390
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9391
0
SLANG_RAW("        OpExtInst $$T result glsl450 Cos $x\n")
9392
0
SLANG_RAW("    };\n")
9393
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cos\";\n")
9394
0
SLANG_RAW("    }\n")
9395
0
SLANG_RAW("}\n")
9396
0
SLANG_RAW("\n")
9397
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9398
0
SLANG_RAW("[__readNone]\n")
9399
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9400
0
SLANG_RAW("vector<T, N> cos(vector<T, N> x)\n")
9401
0
SLANG_RAW("{\n")
9402
0
SLANG_RAW("    __target_switch\n")
9403
0
SLANG_RAW("    {\n")
9404
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cos\";\n")
9405
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cos\";\n")
9406
0
SLANG_RAW("    case metal: __intrinsic_asm \"cos\";\n")
9407
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9408
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Cos $x\n")
9409
0
SLANG_RAW("    };\n")
9410
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cos\";\n")
9411
0
SLANG_RAW("    default:\n")
9412
0
SLANG_RAW("        VECTOR_MAP_UNARY(T,N, cos, x);\n")
9413
0
SLANG_RAW("    }\n")
9414
0
SLANG_RAW("}\n")
9415
0
SLANG_RAW("\n")
9416
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9417
0
SLANG_RAW("[__readNone]\n")
9418
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9419
0
SLANG_RAW("matrix<T, N, M> cos(matrix<T, N, M> x)\n")
9420
0
SLANG_RAW("{\n")
9421
0
SLANG_RAW("    __target_switch\n")
9422
0
SLANG_RAW("    {\n")
9423
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cos\";\n")
9424
0
SLANG_RAW("    default:\n")
9425
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, cos, x);\n")
9426
0
SLANG_RAW("    }\n")
9427
0
SLANG_RAW("}\n")
9428
0
SLANG_RAW("\n")
9429
0
SLANG_RAW("/// Hyperbolic cosine. Returns the hyperbolic cosine of the specified value.\n")
9430
0
SLANG_RAW("/// @param x The specified value.\n")
9431
0
SLANG_RAW("/// @return The hyperbolic cosine of the specified value.\n")
9432
0
SLANG_RAW("/// @category math\n")
9433
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9434
0
SLANG_RAW("[__readNone]\n")
9435
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9436
0
SLANG_RAW("T cosh(T x)\n")
9437
0
SLANG_RAW("{\n")
9438
0
SLANG_RAW("    __target_switch\n")
9439
0
SLANG_RAW("    {\n")
9440
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_cosh($0)\";\n")
9441
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_cosh($0)\";\n")
9442
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cosh\";\n")
9443
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cosh\";\n")
9444
0
SLANG_RAW("    case metal: __intrinsic_asm \"cosh\";\n")
9445
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9446
0
SLANG_RAW("        OpExtInst $$T result glsl450 Cosh $x\n")
9447
0
SLANG_RAW("    };\n")
9448
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cosh\";\n")
9449
0
SLANG_RAW("    }\n")
9450
0
SLANG_RAW("}\n")
9451
0
SLANG_RAW("\n")
9452
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9453
0
SLANG_RAW("[__readNone]\n")
9454
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9455
0
SLANG_RAW("vector<T,N> cosh(vector<T,N> x)\n")
9456
0
SLANG_RAW("{\n")
9457
0
SLANG_RAW("    __target_switch\n")
9458
0
SLANG_RAW("    {\n")
9459
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cosh\";\n")
9460
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cosh\";\n")
9461
0
SLANG_RAW("    case metal: __intrinsic_asm \"cosh\";\n")
9462
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9463
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Cosh $x\n")
9464
0
SLANG_RAW("    };\n")
9465
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cosh\";\n")
9466
0
SLANG_RAW("    default:\n")
9467
0
SLANG_RAW("        VECTOR_MAP_UNARY(T,N, cosh, x);\n")
9468
0
SLANG_RAW("    }\n")
9469
0
SLANG_RAW("}\n")
9470
0
SLANG_RAW("\n")
9471
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9472
0
SLANG_RAW("[__readNone]\n")
9473
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9474
0
SLANG_RAW("matrix<T, N, M> cosh(matrix<T, N, M> x)\n")
9475
0
SLANG_RAW("{\n")
9476
0
SLANG_RAW("    __target_switch\n")
9477
0
SLANG_RAW("    {\n")
9478
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cosh\";\n")
9479
0
SLANG_RAW("    default:\n")
9480
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, cosh, x);\n")
9481
0
SLANG_RAW("    }\n")
9482
0
SLANG_RAW("}\n")
9483
0
SLANG_RAW("\n")
9484
0
SLANG_RAW("/// Compute the cosine of pi times the input.\n")
9485
0
SLANG_RAW("/// @param x The input value.\n")
9486
0
SLANG_RAW("/// @return The cosine of pi times the input.\n")
9487
0
SLANG_RAW("/// @remarks This function is equivalent to `cos(PI * x)`. On Metal, this function is implemented using the `cospi` intrinsic.\n")
9488
0
SLANG_RAW("/// @category math\n")
9489
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9490
0
SLANG_RAW("[__readNone]\n")
9491
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9492
0
SLANG_RAW("T cospi(T x)\n")
9493
0
SLANG_RAW("{\n")
9494
0
SLANG_RAW("    __target_switch\n")
9495
0
SLANG_RAW("    {\n")
9496
0
SLANG_RAW("    case metal: __intrinsic_asm \"cospi\";\n")
9497
0
SLANG_RAW("    default:\n")
9498
0
SLANG_RAW("        return cos(T.getPi() * x);\n")
9499
0
SLANG_RAW("    }\n")
9500
0
SLANG_RAW("}\n")
9501
0
SLANG_RAW("\n")
9502
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
9503
0
SLANG_RAW("[__readNone]\n")
9504
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9505
0
SLANG_RAW("vector<T,N> cospi(vector<T,N> x)\n")
9506
0
SLANG_RAW("{\n")
9507
0
SLANG_RAW("    __target_switch\n")
9508
0
SLANG_RAW("    {\n")
9509
0
SLANG_RAW("    case metal: __intrinsic_asm \"cospi\";\n")
9510
0
SLANG_RAW("    default:\n")
9511
0
SLANG_RAW("        return cos(T.getPi() * x);\n")
9512
0
SLANG_RAW("    }\n")
9513
0
SLANG_RAW("}\n")
9514
0
SLANG_RAW("\n")
9515
0
SLANG_RAW("// emulate 64-bit countbits when not natively supported.\n")
9516
0
SLANG_RAW("[__readNone]\n")
9517
0
SLANG_RAW("[ForceInline]\n")
9518
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
9519
0
SLANG_RAW("internal uint __emulatedCountbits64(uint64_t value)\n")
9520
0
SLANG_RAW("{\n")
9521
0
SLANG_RAW("    uint2 value_uint2 = bit_cast<uint2>(value);\n")
9522
0
SLANG_RAW("    uint2 counted_bits_uint2 = countbits(value_uint2);\n")
9523
0
SLANG_RAW("    return counted_bits_uint2.x + counted_bits_uint2.y;\n")
9524
0
SLANG_RAW("}\n")
9525
0
SLANG_RAW("\n")
9526
0
SLANG_RAW("/// Population count.\n")
9527
0
SLANG_RAW("/// Counts the number of set bits in the binary representation of a value.\n")
9528
0
SLANG_RAW("/// @param value The value to count bits in.\n")
9529
0
SLANG_RAW("/// @return The number of bits in the binary representation of `value` that are set to one.\n")
9530
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpBitCount`.\n")
9531
0
SLANG_RAW("/// @category bitops\n")
9532
0
SLANG_RAW("[__readNone]\n")
9533
0
SLANG_RAW("[ForceInline]\n")
9534
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
9535
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
9536
0
SLANG_RAW("uint countbits(T value)\n")
9537
0
SLANG_RAW("{\n")
9538
0
SLANG_RAW("    // Emulate 8-bit support\n")
9539
0
SLANG_RAW("    // 8-bit support is not currently supported anywhere natively\n")
9540
0
SLANG_RAW("    if (T is int8_t || T  is uint8_t)\n")
9541
0
SLANG_RAW("    {\n")
9542
0
SLANG_RAW("        return countbits(__intCast<uint32_t>(value));\n")
9543
0
SLANG_RAW("    }\n")
9544
0
SLANG_RAW("\n")
9545
0
SLANG_RAW("    __target_switch\n")
9546
0
SLANG_RAW("    {\n")
9547
0
SLANG_RAW("    case hlsl:\n")
9548
0
SLANG_RAW("        // 64-bit support dependent on SM6.0 and dxil\n")
9549
0
SLANG_RAW("        // 16-bit support dependent on SM6.2 and dxil\n")
9550
0
SLANG_RAW("        __intrinsic_asm \"countbits\";\n")
9551
0
SLANG_RAW("    case glsl:\n")
9552
0
SLANG_RAW("        if(T is int64_t || T  is uint64_t)\n")
9553
0
SLANG_RAW("        {\n")
9554
0
SLANG_RAW("            return __emulatedCountbits64(__intCast<uint64_t>(value));\n")
9555
0
SLANG_RAW("        }\n")
9556
0
SLANG_RAW("        else if (T is int16_t || T  is uint16_t)\n")
9557
0
SLANG_RAW("        {\n")
9558
0
SLANG_RAW("            // emulate 16-bit\n")
9559
0
SLANG_RAW("            return countbits(__intCast<uint32_t>(value));\n")
9560
0
SLANG_RAW("        }\n")
9561
0
SLANG_RAW("        else\n")
9562
0
SLANG_RAW("        {\n")
9563
0
SLANG_RAW("            // bitCount only supports 32-bit\n")
9564
0
SLANG_RAW("            __intrinsic_asm \"bitCount\";\n")
9565
0
SLANG_RAW("        }\n")
9566
0
SLANG_RAW("    case metal:\n")
9567
0
SLANG_RAW("        __intrinsic_asm \"($TR)popcount($0)\";\n")
9568
0
SLANG_RAW("    case cuda:\n")
9569
0
SLANG_RAW("    case cpp:\n")
9570
0
SLANG_RAW("        __intrinsic_asm \"$P_countbits($0)\";\n")
9571
0
SLANG_RAW("    case spirv:\n")
9572
0
SLANG_RAW("        if(T is int64_t || T  is uint64_t)\n")
9573
0
SLANG_RAW("        {\n")
9574
0
SLANG_RAW("            return __emulatedCountbits64(__intCast<uint64_t>(value));\n")
9575
0
SLANG_RAW("        }\n")
9576
0
SLANG_RAW("        else if (T is int16_t || T  is uint16_t)\n")
9577
0
SLANG_RAW("        {\n")
9578
0
SLANG_RAW("            // emulate 16-bit\n")
9579
0
SLANG_RAW("            return countbits(__intCast<uint32_t>(value));\n")
9580
0
SLANG_RAW("        }\n")
9581
0
SLANG_RAW("        else\n")
9582
0
SLANG_RAW("        {\n")
9583
0
SLANG_RAW("            // OpBitCount only supports 32-bit\n")
9584
0
SLANG_RAW("            return spirv_asm {OpBitCount $$uint result $value};\n")
9585
0
SLANG_RAW("        }\n")
9586
0
SLANG_RAW("    case wgsl:\n")
9587
0
SLANG_RAW("            // wgsl only supports 32-bit integers\n")
9588
0
SLANG_RAW("            if (T is int32_t)\n")
9589
0
SLANG_RAW("            {\n")
9590
0
SLANG_RAW("                // wgsl countOneBits returns the same type as the\n")
9591
0
SLANG_RAW("                // one it was given. Cast signed ints to unsigned\n")
9592
0
SLANG_RAW("                // so we can provide the correct return value.\n")
9593
0
SLANG_RAW("                return countbits(__intCast<uint32_t>(value));\n")
9594
0
SLANG_RAW("            }\n")
9595
0
SLANG_RAW("            __intrinsic_asm \"countOneBits\";\n")
9596
0
SLANG_RAW("    }\n")
9597
0
SLANG_RAW("}\n")
9598
0
SLANG_RAW("\n")
9599
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
9600
0
SLANG_RAW("[__readNone]\n")
9601
0
SLANG_RAW("[ForceInline]\n")
9602
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
9603
0
SLANG_RAW("vector<uint, N> countbits(vector<T, N> value)\n")
9604
0
SLANG_RAW("{\n")
9605
0
SLANG_RAW("    // Emulate 8-bit support\n")
9606
0
SLANG_RAW("    // 8-bit support is not currently supported anywhere natively\n")
9607
0
SLANG_RAW("    if (T is int8_t || T  is uint8_t)\n")
9608
0
SLANG_RAW("    {\n")
9609
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, countbits, value);\n")
9610
0
SLANG_RAW("    }\n")
9611
0
SLANG_RAW("\n")
9612
0
SLANG_RAW("    __target_switch\n")
9613
0
SLANG_RAW("    {\n")
9614
0
SLANG_RAW("    case hlsl:\n")
9615
0
SLANG_RAW("        __intrinsic_asm \"countbits\";\n")
9616
0
SLANG_RAW("    case glsl:\n")
9617
0
SLANG_RAW("        if(T is int64_t || T  is uint64_t || T is int16_t || T  is uint16_t)\n")
9618
0
SLANG_RAW("        {\n")
9619
0
SLANG_RAW("            // Emulate 64-bit and 16-bit\n")
9620
0
SLANG_RAW("            VECTOR_MAP_UNARY(uint, N, countbits, value);\n")
9621
0
SLANG_RAW("        }\n")
9622
0
SLANG_RAW("        else\n")
9623
0
SLANG_RAW("        {\n")
9624
0
SLANG_RAW("            __intrinsic_asm \"bitCount\";\n")
9625
0
SLANG_RAW("        }\n")
9626
0
SLANG_RAW("    case metal:\n")
9627
0
SLANG_RAW("        __intrinsic_asm \"($TR)popcount($0)\";\n")
9628
0
SLANG_RAW("    case spirv:\n")
9629
0
SLANG_RAW("        if(T is int64_t || T  is uint64_t || T is int16_t || T  is uint16_t)\n")
9630
0
SLANG_RAW("        {\n")
9631
0
SLANG_RAW("            // Emulate 64-bit and 16-bit\n")
9632
0
SLANG_RAW("            VECTOR_MAP_UNARY(uint, N, countbits, value);\n")
9633
0
SLANG_RAW("        }\n")
9634
0
SLANG_RAW("        else\n")
9635
0
SLANG_RAW("        {\n")
9636
0
SLANG_RAW("            return spirv_asm {OpBitCount $$vector<uint, N> result $value};\n")
9637
0
SLANG_RAW("        }\n")
9638
0
SLANG_RAW("    case wgsl:\n")
9639
0
SLANG_RAW("        // wgsl only supports 32-bit integers\n")
9640
0
SLANG_RAW("        if (T is int32_t)\n")
9641
0
SLANG_RAW("        {\n")
9642
0
SLANG_RAW("            vector<uint32_t, N> ret;\n")
9643
0
SLANG_RAW("            for (int i = 0; i < N; i++)\n")
9644
0
SLANG_RAW("            {\n")
9645
0
SLANG_RAW("                ret[i] = countbits(__intCast<uint32_t>(value[i]));\n")
9646
0
SLANG_RAW("            }\n")
9647
0
SLANG_RAW("            return ret;\n")
9648
0
SLANG_RAW("        }\n")
9649
0
SLANG_RAW("            __intrinsic_asm \"countOneBits\";\n")
9650
0
SLANG_RAW("    default:\n")
9651
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, countbits, value);\n")
9652
0
SLANG_RAW("    }\n")
9653
0
SLANG_RAW("}\n")
9654
0
SLANG_RAW("\n")
9655
0
SLANG_RAW("/// Cross product. Returns the cross product of two 3D vectors.\n")
9656
0
SLANG_RAW("/// @param left The first vector.\n")
9657
0
SLANG_RAW("/// @param right The second vector.\n")
9658
0
SLANG_RAW("/// @return The cross product of `left` and `right`.\n")
9659
0
SLANG_RAW("/// @category math\n")
9660
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9661
0
SLANG_RAW("[__readNone]\n")
9662
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9663
0
SLANG_RAW("vector<T,3> cross(vector<T,3> left, vector<T,3> right)\n")
9664
0
SLANG_RAW("{\n")
9665
0
SLANG_RAW("    // TODO: SPIRV does not support integer vectors.\n")
9666
0
SLANG_RAW("    __target_switch\n")
9667
0
SLANG_RAW("    {\n")
9668
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cross\";\n")
9669
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cross\";\n")
9670
0
SLANG_RAW("    case metal: __intrinsic_asm \"cross\";\n")
9671
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9672
0
SLANG_RAW("        OpExtInst $$vector<T,3> result glsl450 Cross $left $right\n")
9673
0
SLANG_RAW("    };\n")
9674
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cross\";\n")
9675
0
SLANG_RAW("    default:\n")
9676
0
SLANG_RAW("        return vector<T,3>(\n")
9677
0
SLANG_RAW("            left.y * right.z - left.z * right.y,\n")
9678
0
SLANG_RAW("            left.z * right.x - left.x * right.z,\n")
9679
0
SLANG_RAW("            left.x * right.y - left.y * right.x);\n")
9680
0
SLANG_RAW("    }\n")
9681
0
SLANG_RAW("}\n")
9682
0
SLANG_RAW("\n")
9683
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
9684
0
SLANG_RAW("[__readNone]\n")
9685
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9686
0
SLANG_RAW("vector<T, 3> cross(vector<T, 3> left, vector<T, 3> right)\n")
9687
0
SLANG_RAW("{\n")
9688
0
SLANG_RAW("    __target_switch\n")
9689
0
SLANG_RAW("    {\n")
9690
0
SLANG_RAW("    case glsl: __intrinsic_asm \"cross\";\n")
9691
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"cross\";\n")
9692
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
9693
0
SLANG_RAW("        OpExtInst $$vector<T, 3> result glsl450 Cross $left $right\n")
9694
0
SLANG_RAW("    };\n")
9695
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"cross\";\n")
9696
0
SLANG_RAW("    default:\n")
9697
0
SLANG_RAW("        return vector<T, 3>(\n")
9698
0
SLANG_RAW("            left.y * right.z - left.z * right.y,\n")
9699
0
SLANG_RAW("            left.z * right.x - left.x * right.z,\n")
9700
0
SLANG_RAW("            left.x * right.y - left.y * right.x);\n")
9701
0
SLANG_RAW("    }\n")
9702
0
SLANG_RAW("}\n")
9703
0
SLANG_RAW("\n")
9704
0
SLANG_RAW("// Convert encoded color\n")
9705
0
SLANG_RAW("[__readNone]\n")
9706
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
9707
0
SLANG_RAW("int4 D3DCOLORtoUBYTE4(float4 color)\n")
9708
0
SLANG_RAW("{\n")
9709
0
SLANG_RAW("    __target_switch\n")
9710
0
SLANG_RAW("    {\n")
9711
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"D3DCOLORtoUBYTE4\";\n")
9712
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"bitcast<vec4i>(pack4x8unorm($0)).zyxw\";\n")
9713
0
SLANG_RAW("    default:\n")
9714
0
SLANG_RAW("        let scaled = color.zyxw * 255.001999f;\n")
9715
0
SLANG_RAW("        return int4(scaled);\n")
9716
0
SLANG_RAW("    }\n")
9717
0
SLANG_RAW("}\n")
9718
0
SLANG_RAW("\n")
9719
0
SLANG_RAW("// Partial-difference derivatives\n")
9720
9721
0
const char* diffDimensions[2] = {"x", "y"};
9722
0
for (auto xOrY : diffDimensions) {
9723
0
SLANG_RAW("#line 8462 \"hlsl.meta.slang\"")
9724
0
SLANG_RAW("\n")
9725
0
SLANG_RAW("/// Take the partial derivative of `p` with respect to ")
9726
0
SLANG_SPLICE(xOrY
9727
0
)
9728
0
SLANG_RAW(" in screen space.\n")
9729
0
SLANG_RAW("/// @param p The value to take partial derivative for.\n")
9730
0
SLANG_RAW("/// @return The partial derivative of `p`.\n")
9731
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpDPd")
9732
0
SLANG_SPLICE(xOrY
9733
0
)
9734
0
SLANG_RAW("`.\n")
9735
0
SLANG_RAW("/// @category derivative Derivative functions\n")
9736
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9737
0
SLANG_RAW("[__readNone]\n")
9738
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, fragmentprocessing)]\n")
9739
0
SLANG_RAW("T dd")
9740
0
SLANG_SPLICE(xOrY
9741
0
)
9742
0
SLANG_RAW("(T p)\n")
9743
0
SLANG_RAW("{\n")
9744
0
SLANG_RAW("    __requireComputeDerivative();\n")
9745
0
SLANG_RAW("    __target_switch\n")
9746
0
SLANG_RAW("    {\n")
9747
0
SLANG_RAW("    case hlsl:\n")
9748
0
SLANG_RAW("    case cpp:\n")
9749
0
SLANG_RAW("    case cuda:\n")
9750
0
SLANG_RAW("        __intrinsic_asm \"dd")
9751
0
SLANG_SPLICE(xOrY
9752
0
)
9753
0
SLANG_RAW("\";\n")
9754
0
SLANG_RAW("    case glsl:\n")
9755
0
SLANG_RAW("        __intrinsic_asm \"dFd")
9756
0
SLANG_SPLICE(xOrY
9757
0
)
9758
0
SLANG_RAW("\";\n")
9759
0
SLANG_RAW("    case metal:\n")
9760
0
SLANG_RAW("        __intrinsic_asm \"dfd")
9761
0
SLANG_SPLICE(xOrY
9762
0
)
9763
0
SLANG_RAW("\";\n")
9764
0
SLANG_RAW("    case spirv:\n")
9765
0
SLANG_RAW("        return spirv_asm {OpDPd")
9766
0
SLANG_SPLICE(xOrY
9767
0
)
9768
0
SLANG_RAW(" $$T result $p};\n")
9769
0
SLANG_RAW("    case wgsl:\n")
9770
0
SLANG_RAW("        __intrinsic_asm \"dpd")
9771
0
SLANG_SPLICE(xOrY
9772
0
)
9773
0
SLANG_RAW("\";\n")
9774
0
SLANG_RAW("    }\n")
9775
0
SLANG_RAW("}\n")
9776
0
SLANG_RAW("\n")
9777
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9778
0
SLANG_RAW("[__readNone]\n")
9779
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, fragmentprocessing)]\n")
9780
0
SLANG_RAW("vector<T, N> dd")
9781
0
SLANG_SPLICE(xOrY
9782
0
)
9783
0
SLANG_RAW("(vector<T, N> p)\n")
9784
0
SLANG_RAW("{\n")
9785
0
SLANG_RAW("    __requireComputeDerivative();\n")
9786
0
SLANG_RAW("    __target_switch\n")
9787
0
SLANG_RAW("    {\n")
9788
0
SLANG_RAW("    case hlsl:\n")
9789
0
SLANG_RAW("    case cpp:\n")
9790
0
SLANG_RAW("    case cuda:\n")
9791
0
SLANG_RAW("        __intrinsic_asm \"dd")
9792
0
SLANG_SPLICE(xOrY
9793
0
)
9794
0
SLANG_RAW("\";\n")
9795
0
SLANG_RAW("    case glsl:\n")
9796
0
SLANG_RAW("        __intrinsic_asm \"dFd")
9797
0
SLANG_SPLICE(xOrY
9798
0
)
9799
0
SLANG_RAW("\";\n")
9800
0
SLANG_RAW("    case metal:\n")
9801
0
SLANG_RAW("        __intrinsic_asm \"dfd")
9802
0
SLANG_SPLICE(xOrY
9803
0
)
9804
0
SLANG_RAW("\";\n")
9805
0
SLANG_RAW("    case spirv:\n")
9806
0
SLANG_RAW("        return spirv_asm {OpDPd")
9807
0
SLANG_SPLICE(xOrY
9808
0
)
9809
0
SLANG_RAW(" $$vector<T, N> result $p};\n")
9810
0
SLANG_RAW("    case wgsl:\n")
9811
0
SLANG_RAW("        __intrinsic_asm \"dpd")
9812
0
SLANG_SPLICE(xOrY
9813
0
)
9814
0
SLANG_RAW("\";\n")
9815
0
SLANG_RAW("    }\n")
9816
0
SLANG_RAW("}\n")
9817
0
SLANG_RAW("\n")
9818
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9819
0
SLANG_RAW("[__readNone]\n")
9820
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, fragmentprocessing)]\n")
9821
0
SLANG_RAW("matrix<T, N, M> dd")
9822
0
SLANG_SPLICE(xOrY
9823
0
)
9824
0
SLANG_RAW("(matrix<T, N, M> p)\n")
9825
0
SLANG_RAW("{\n")
9826
0
SLANG_RAW("    __requireComputeDerivative();\n")
9827
0
SLANG_RAW("    __target_switch\n")
9828
0
SLANG_RAW("    {\n")
9829
0
SLANG_RAW("    case hlsl:\n")
9830
0
SLANG_RAW("        __intrinsic_asm \"dd")
9831
0
SLANG_SPLICE(xOrY
9832
0
)
9833
0
SLANG_RAW("\";\n")
9834
0
SLANG_RAW("    default:\n")
9835
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, dd")
9836
0
SLANG_SPLICE(xOrY
9837
0
)
9838
0
SLANG_RAW(", p);\n")
9839
0
SLANG_RAW("    }\n")
9840
0
SLANG_RAW("}\n")
9841
0
SLANG_RAW("\n")
9842
0
SLANG_RAW("/// Take the coarse partial derivative of `p` with respect to ")
9843
0
SLANG_SPLICE(xOrY
9844
0
)
9845
0
SLANG_RAW(" in screen space.\n")
9846
0
SLANG_RAW("/// @param p The value to take partial derivative for.\n")
9847
0
SLANG_RAW("/// @return The partial derivative of `p`.\n")
9848
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpDPd")
9849
0
SLANG_SPLICE(xOrY
9850
0
)
9851
0
SLANG_RAW("Coarse`.\n")
9852
0
SLANG_RAW("/// @category derivative\n")
9853
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9854
0
SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n")
9855
0
SLANG_RAW("[__readNone]\n")
9856
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9857
0
SLANG_RAW("T dd")
9858
0
SLANG_SPLICE(xOrY
9859
0
)
9860
0
SLANG_RAW("_coarse(T p)\n")
9861
0
SLANG_RAW("{\n")
9862
0
SLANG_RAW("    __requireComputeDerivative();\n")
9863
0
SLANG_RAW("    __target_switch\n")
9864
0
SLANG_RAW("    {\n")
9865
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dd")
9866
0
SLANG_SPLICE(xOrY
9867
0
)
9868
0
SLANG_RAW("_coarse\";\n")
9869
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dFd")
9870
0
SLANG_SPLICE(xOrY
9871
0
)
9872
0
SLANG_RAW("Coarse\";\n")
9873
0
SLANG_RAW("    case spirv: return spirv_asm {OpCapability DerivativeControl; result:$$T = OpDPd")
9874
0
SLANG_SPLICE(xOrY
9875
0
)
9876
0
SLANG_RAW("Coarse $p};\n")
9877
0
SLANG_RAW("    }\n")
9878
0
SLANG_RAW("}\n")
9879
0
SLANG_RAW("\n")
9880
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9881
0
SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n")
9882
0
SLANG_RAW("[__readNone]\n")
9883
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9884
0
SLANG_RAW("vector<T, N> dd")
9885
0
SLANG_SPLICE(xOrY
9886
0
)
9887
0
SLANG_RAW("_coarse(vector<T, N> p)\n")
9888
0
SLANG_RAW("{\n")
9889
0
SLANG_RAW("    __requireComputeDerivative();\n")
9890
0
SLANG_RAW("    __target_switch\n")
9891
0
SLANG_RAW("    {\n")
9892
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dd")
9893
0
SLANG_SPLICE(xOrY
9894
0
)
9895
0
SLANG_RAW("_coarse\";\n")
9896
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dFd")
9897
0
SLANG_SPLICE(xOrY
9898
0
)
9899
0
SLANG_RAW("Coarse\";\n")
9900
0
SLANG_RAW("    case spirv: return spirv_asm {OpCapability DerivativeControl; result:$$vector<T,N> = OpDPd")
9901
0
SLANG_SPLICE(xOrY
9902
0
)
9903
0
SLANG_RAW("Coarse $p};\n")
9904
0
SLANG_RAW("    }\n")
9905
0
SLANG_RAW("}\n")
9906
0
SLANG_RAW("\n")
9907
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9908
0
SLANG_RAW("[__readNone]\n")
9909
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9910
0
SLANG_RAW("matrix<T, N, M> dd")
9911
0
SLANG_SPLICE(xOrY
9912
0
)
9913
0
SLANG_RAW("_coarse(matrix<T, N, M> p)\n")
9914
0
SLANG_RAW("{\n")
9915
0
SLANG_RAW("    __requireComputeDerivative();\n")
9916
0
SLANG_RAW("    __target_switch\n")
9917
0
SLANG_RAW("    {\n")
9918
0
SLANG_RAW("    case hlsl:\n")
9919
0
SLANG_RAW("        __intrinsic_asm \"dd")
9920
0
SLANG_SPLICE(xOrY
9921
0
)
9922
0
SLANG_RAW("_coarse\";\n")
9923
0
SLANG_RAW("    default:\n")
9924
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, dd")
9925
0
SLANG_SPLICE(xOrY
9926
0
)
9927
0
SLANG_RAW("_coarse, p);\n")
9928
0
SLANG_RAW("    }\n")
9929
0
SLANG_RAW("}\n")
9930
0
SLANG_RAW("\n")
9931
0
SLANG_RAW("/// Take the fine partial derivative of `p` with respect to ")
9932
0
SLANG_SPLICE(xOrY
9933
0
)
9934
0
SLANG_RAW(" in screen space.\n")
9935
0
SLANG_RAW("/// @param p The value to take partial derivative for.\n")
9936
0
SLANG_RAW("/// @return The partial derivative of `p`.\n")
9937
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpDPd")
9938
0
SLANG_SPLICE(xOrY
9939
0
)
9940
0
SLANG_RAW("Fine`.\n")
9941
0
SLANG_RAW("/// @category derivative\n")
9942
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
9943
0
SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n")
9944
0
SLANG_RAW("[__readNone]\n")
9945
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9946
0
SLANG_RAW("T dd")
9947
0
SLANG_SPLICE(xOrY
9948
0
)
9949
0
SLANG_RAW("_fine(T p)\n")
9950
0
SLANG_RAW("{\n")
9951
0
SLANG_RAW("    __requireComputeDerivative();\n")
9952
0
SLANG_RAW("    __target_switch\n")
9953
0
SLANG_RAW("    {\n")
9954
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dd")
9955
0
SLANG_SPLICE(xOrY
9956
0
)
9957
0
SLANG_RAW("_fine\";\n")
9958
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dFd")
9959
0
SLANG_SPLICE(xOrY
9960
0
)
9961
0
SLANG_RAW("Fine\";\n")
9962
0
SLANG_RAW("    case spirv: return spirv_asm {OpCapability DerivativeControl; result:$$T = OpDPd")
9963
0
SLANG_SPLICE(xOrY
9964
0
)
9965
0
SLANG_RAW("Fine $p};\n")
9966
0
SLANG_RAW("    }\n")
9967
0
SLANG_RAW("}\n")
9968
0
SLANG_RAW("\n")
9969
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
9970
0
SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n")
9971
0
SLANG_RAW("[__readNone]\n")
9972
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9973
0
SLANG_RAW("vector<T, N> dd")
9974
0
SLANG_SPLICE(xOrY
9975
0
)
9976
0
SLANG_RAW("_fine(vector<T, N> p)\n")
9977
0
SLANG_RAW("{\n")
9978
0
SLANG_RAW("    __requireComputeDerivative();\n")
9979
0
SLANG_RAW("    __target_switch\n")
9980
0
SLANG_RAW("    {\n")
9981
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dd")
9982
0
SLANG_SPLICE(xOrY
9983
0
)
9984
0
SLANG_RAW("_fine\";\n")
9985
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dFd")
9986
0
SLANG_SPLICE(xOrY
9987
0
)
9988
0
SLANG_RAW("Fine\";\n")
9989
0
SLANG_RAW("    case spirv: return spirv_asm {OpCapability DerivativeControl; result:$$vector<T,N> = OpDPd")
9990
0
SLANG_SPLICE(xOrY
9991
0
)
9992
0
SLANG_RAW("Fine $p};\n")
9993
0
SLANG_RAW("    }\n")
9994
0
SLANG_RAW("}\n")
9995
0
SLANG_RAW("\n")
9996
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
9997
0
SLANG_RAW("[__readNone]\n")
9998
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
9999
0
SLANG_RAW("matrix<T, N, M> dd")
10000
0
SLANG_SPLICE(xOrY
10001
0
)
10002
0
SLANG_RAW("_fine(matrix<T, N, M> p)\n")
10003
0
SLANG_RAW("{\n")
10004
0
SLANG_RAW("    __requireComputeDerivative();\n")
10005
0
SLANG_RAW("    __target_switch\n")
10006
0
SLANG_RAW("    {\n")
10007
0
SLANG_RAW("    case hlsl:\n")
10008
0
SLANG_RAW("        __intrinsic_asm \"dd")
10009
0
SLANG_SPLICE(xOrY
10010
0
)
10011
0
SLANG_RAW("_fine\";\n")
10012
0
SLANG_RAW("    default:\n")
10013
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, dd")
10014
0
SLANG_SPLICE(xOrY
10015
0
)
10016
0
SLANG_RAW("_fine, p);\n")
10017
0
SLANG_RAW("    }\n")
10018
0
SLANG_RAW("}\n")
10019
0
SLANG_RAW("\n")
10020
10021
0
} // for (xOrY)
10022
0
SLANG_RAW("#line 8631 \"hlsl.meta.slang\"")
10023
0
SLANG_RAW("\n")
10024
0
SLANG_RAW("\n")
10025
0
SLANG_RAW("\n")
10026
0
SLANG_RAW("/// Convert radians to degrees.\n")
10027
0
SLANG_RAW("/// @param x The angle in radians.\n")
10028
0
SLANG_RAW("/// @return The angle in degrees.\n")
10029
0
SLANG_RAW("/// @category math\n")
10030
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10031
0
SLANG_RAW("[__readNone]\n")
10032
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10033
0
SLANG_RAW("T degrees(T x)\n")
10034
0
SLANG_RAW("{\n")
10035
0
SLANG_RAW("    __target_switch\n")
10036
0
SLANG_RAW("    {\n")
10037
0
SLANG_RAW("    case glsl: __intrinsic_asm \"degrees\";\n")
10038
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"degrees\";\n")
10039
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10040
0
SLANG_RAW("        OpExtInst $$T result glsl450 Degrees $x\n")
10041
0
SLANG_RAW("    };\n")
10042
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"degrees\";\n")
10043
0
SLANG_RAW("    default:\n")
10044
0
SLANG_RAW("        return x * (T(180) / T.getPi());\n")
10045
0
SLANG_RAW("    }\n")
10046
0
SLANG_RAW("}\n")
10047
0
SLANG_RAW("\n")
10048
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10049
0
SLANG_RAW("[__readNone]\n")
10050
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10051
0
SLANG_RAW("vector<T, N> degrees(vector<T, N> x)\n")
10052
0
SLANG_RAW("{\n")
10053
0
SLANG_RAW("    __target_switch\n")
10054
0
SLANG_RAW("    {\n")
10055
0
SLANG_RAW("    case glsl: __intrinsic_asm \"degrees\";\n")
10056
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"degrees\";\n")
10057
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10058
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Degrees $x\n")
10059
0
SLANG_RAW("    };\n")
10060
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"degrees\";\n")
10061
0
SLANG_RAW("    default:\n")
10062
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, degrees, x);\n")
10063
0
SLANG_RAW("    }\n")
10064
0
SLANG_RAW("}\n")
10065
0
SLANG_RAW("\n")
10066
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
10067
0
SLANG_RAW("[__readNone]\n")
10068
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10069
0
SLANG_RAW("matrix<T, N, M> degrees(matrix<T, N, M> x)\n")
10070
0
SLANG_RAW("{\n")
10071
0
SLANG_RAW("    __target_switch\n")
10072
0
SLANG_RAW("    {\n")
10073
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"degrees\";\n")
10074
0
SLANG_RAW("    default:\n")
10075
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, degrees, x);\n")
10076
0
SLANG_RAW("    }\n")
10077
0
SLANG_RAW("}\n")
10078
0
SLANG_RAW("\n")
10079
0
SLANG_RAW("/// Compute matrix determinant.\n")
10080
0
SLANG_RAW("/// @param m The matrix.\n")
10081
0
SLANG_RAW("/// @return The determinant of the matrix.\n")
10082
0
SLANG_RAW("/// @category math\n")
10083
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10084
0
SLANG_RAW("[__readNone]\n")
10085
0
SLANG_RAW("[PreferCheckpoint]\n")
10086
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10087
0
SLANG_RAW("T determinant(matrix<T,N,N> m)\n")
10088
0
SLANG_RAW("{\n")
10089
0
SLANG_RAW("    __target_switch\n")
10090
0
SLANG_RAW("    {\n")
10091
0
SLANG_RAW("    case glsl: __intrinsic_asm \"determinant\";\n")
10092
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"determinant\";\n")
10093
0
SLANG_RAW("    case metal: __intrinsic_asm \"determinant\";\n")
10094
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10095
0
SLANG_RAW("        OpExtInst $$T result glsl450 Determinant $m\n")
10096
0
SLANG_RAW("    };\n")
10097
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"determinant\";\n")
10098
0
SLANG_RAW("    case cuda:\n")
10099
0
SLANG_RAW("    default:\n")
10100
0
SLANG_RAW("        static_assert(N >= 1 && N <= 4, \"determinant is only implemented up to 4x4 matrices\");\n")
10101
0
SLANG_RAW("        if (N == 1)\n")
10102
0
SLANG_RAW("        {\n")
10103
0
SLANG_RAW("            return m[0][0];\n")
10104
0
SLANG_RAW("        }\n")
10105
0
SLANG_RAW("        else if (N == 2)\n")
10106
0
SLANG_RAW("        {\n")
10107
0
SLANG_RAW("            return m[0][0] * m[1][1] - m[0][1] * m[1][0];\n")
10108
0
SLANG_RAW("        }\n")
10109
0
SLANG_RAW("        else if (N == 3)\n")
10110
0
SLANG_RAW("        {\n")
10111
0
SLANG_RAW("            return\n")
10112
0
SLANG_RAW("                m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])\n")
10113
0
SLANG_RAW("              - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])\n")
10114
0
SLANG_RAW("              + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);\n")
10115
0
SLANG_RAW("        }\n")
10116
0
SLANG_RAW("        else// if (N == 4)\n")
10117
0
SLANG_RAW("        {\n")
10118
0
SLANG_RAW("            T a = m[2][2] * m[3][3] - m[2][3] * m[3][2];\n")
10119
0
SLANG_RAW("            T b = m[2][1] * m[3][3] - m[2][3] * m[3][1];\n")
10120
0
SLANG_RAW("            T c = m[2][1] * m[3][2] - m[2][2] * m[3][1];\n")
10121
0
SLANG_RAW("            T d = m[2][0] * m[3][3] - m[2][3] * m[3][0];\n")
10122
0
SLANG_RAW("            T e = m[2][0] * m[3][2] - m[2][2] * m[3][0];\n")
10123
0
SLANG_RAW("            T f = m[2][0] * m[3][1] - m[2][1] * m[3][0];\n")
10124
0
SLANG_RAW("            return\n")
10125
0
SLANG_RAW("                m[0][0] * (m[1][1] * a - m[1][2] * b + m[1][3] * c)\n")
10126
0
SLANG_RAW("              - m[0][1] * (m[1][0] * a - m[1][2] * d + m[1][3] * e)\n")
10127
0
SLANG_RAW("              + m[0][2] * (m[1][0] * b - m[1][1] * d + m[1][3] * f)\n")
10128
0
SLANG_RAW("              - m[0][3] * (m[1][0] * c - m[1][1] * e + m[1][2] * f);\n")
10129
0
SLANG_RAW("        }\n")
10130
0
SLANG_RAW("    }\n")
10131
0
SLANG_RAW("}\n")
10132
0
SLANG_RAW("\n")
10133
0
SLANG_RAW("/// @param m The matrix.\n")
10134
0
SLANG_RAW("/// @return The determinant of the matrix.\n")
10135
0
SLANG_RAW("/// @category math\n")
10136
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
10137
0
SLANG_RAW("[__readNone]\n")
10138
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10139
0
SLANG_RAW("T determinant(matrix<T,N,N> m)\n")
10140
0
SLANG_RAW("{\n")
10141
0
SLANG_RAW("    __target_switch\n")
10142
0
SLANG_RAW("    {\n")
10143
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"determinant\";\n")
10144
0
SLANG_RAW("    // GLSL, WGSL, SPIR-V, and CUDA don't support integer determinants for lowered matrices, so we need to implement it manually\n")
10145
0
SLANG_RAW("    case cuda:\n")
10146
0
SLANG_RAW("    default:\n")
10147
0
SLANG_RAW("        static_assert(N >= 1 && N <= 4, \"determinant is only implemented up to 4x4 matrices\");\n")
10148
0
SLANG_RAW("        if (N == 1)\n")
10149
0
SLANG_RAW("        {\n")
10150
0
SLANG_RAW("            return m[0][0];\n")
10151
0
SLANG_RAW("        }\n")
10152
0
SLANG_RAW("        else if (N == 2)\n")
10153
0
SLANG_RAW("        {\n")
10154
0
SLANG_RAW("            return m[0][0] * m[1][1] - m[0][1] * m[1][0];\n")
10155
0
SLANG_RAW("        }\n")
10156
0
SLANG_RAW("        else if (N == 3)\n")
10157
0
SLANG_RAW("        {\n")
10158
0
SLANG_RAW("            return\n")
10159
0
SLANG_RAW("                m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])\n")
10160
0
SLANG_RAW("              - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])\n")
10161
0
SLANG_RAW("              + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);\n")
10162
0
SLANG_RAW("        }\n")
10163
0
SLANG_RAW("        else// if (N == 4)\n")
10164
0
SLANG_RAW("        {\n")
10165
0
SLANG_RAW("            T a = m[2][2] * m[3][3] - m[2][3] * m[3][2];\n")
10166
0
SLANG_RAW("            T b = m[2][1] * m[3][3] - m[2][3] * m[3][1];\n")
10167
0
SLANG_RAW("            T c = m[2][1] * m[3][2] - m[2][2] * m[3][1];\n")
10168
0
SLANG_RAW("            T d = m[2][0] * m[3][3] - m[2][3] * m[3][0];\n")
10169
0
SLANG_RAW("            T e = m[2][0] * m[3][2] - m[2][2] * m[3][0];\n")
10170
0
SLANG_RAW("            T f = m[2][0] * m[3][1] - m[2][1] * m[3][0];\n")
10171
0
SLANG_RAW("            return\n")
10172
0
SLANG_RAW("                m[0][0] * (m[1][1] * a - m[1][2] * b + m[1][3] * c)\n")
10173
0
SLANG_RAW("              - m[0][1] * (m[1][0] * a - m[1][2] * d + m[1][3] * e)\n")
10174
0
SLANG_RAW("              + m[0][2] * (m[1][0] * b - m[1][1] * d + m[1][3] * f)\n")
10175
0
SLANG_RAW("              - m[0][3] * (m[1][0] * c - m[1][1] * e + m[1][2] * f);\n")
10176
0
SLANG_RAW("        }\n")
10177
0
SLANG_RAW("    }\n")
10178
0
SLANG_RAW("}\n")
10179
0
SLANG_RAW("\n")
10180
0
SLANG_RAW("/// Barrier for device memory.\n")
10181
0
SLANG_RAW("/// @category barrier\n")
10182
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
10183
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
10184
0
SLANG_RAW("void DeviceMemoryBarrier()\n")
10185
0
SLANG_RAW("{\n")
10186
0
SLANG_RAW("    __target_switch\n")
10187
0
SLANG_RAW("    {\n")
10188
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"DeviceMemoryBarrier\";\n")
10189
0
SLANG_RAW("    case glsl: __intrinsic_asm \"memoryBarrier(gl_ScopeDevice, (gl_StorageSemanticsImage|gl_StorageSemanticsBuffer), gl_SemanticsAcquireRelease)\";\n")
10190
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__threadfence()\";\n")
10191
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup | mem_flags::mem_texture | mem_flags::mem_threadgroup_imageblock)\";\n")
10192
0
SLANG_RAW("    case spirv: spirv_asm\n")
10193
0
SLANG_RAW("        {\n")
10194
0
SLANG_RAW("            OpMemoryBarrier Device AcquireRelease|UniformMemory|ImageMemory;\n")
10195
0
SLANG_RAW("        };\n")
10196
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"storageBarrier(); textureBarrier(); workgroupBarrier();\";\n")
10197
0
SLANG_RAW("    }\n")
10198
0
SLANG_RAW("}\n")
10199
0
SLANG_RAW("\n")
10200
0
SLANG_RAW("/// Barrier for device memory with group synchronization.\n")
10201
0
SLANG_RAW("/// @category barrier\n")
10202
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
10203
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
10204
0
SLANG_RAW("void DeviceMemoryBarrierWithGroupSync()\n")
10205
0
SLANG_RAW("{\n")
10206
0
SLANG_RAW("    __target_switch\n")
10207
0
SLANG_RAW("    {\n")
10208
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"DeviceMemoryBarrierWithGroupSync\";\n")
10209
0
SLANG_RAW("    case glsl: __intrinsic_asm \"controlBarrier(gl_ScopeWorkgroup, gl_ScopeDevice, (gl_StorageSemanticsImage|gl_StorageSemanticsBuffer), gl_SemanticsAcquireRelease)\";\n")
10210
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__syncthreads()\";\n")
10211
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup | mem_flags::mem_texture | mem_flags::mem_threadgroup_imageblock)\";\n")
10212
0
SLANG_RAW("    case spirv: spirv_asm\n")
10213
0
SLANG_RAW("        {\n")
10214
0
SLANG_RAW("            OpControlBarrier Workgroup Device AcquireRelease|UniformMemory|ImageMemory;\n")
10215
0
SLANG_RAW("        };\n")
10216
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"storageBarrier(); textureBarrier(); workgroupBarrier();\";\n")
10217
0
SLANG_RAW("    }\n")
10218
0
SLANG_RAW("}\n")
10219
0
SLANG_RAW("\n")
10220
0
SLANG_RAW("/// Vector distance. Returns the distance between two points.\n")
10221
0
SLANG_RAW("/// @param x The first point.\n")
10222
0
SLANG_RAW("/// @param y The second point.\n")
10223
0
SLANG_RAW("/// @return The distance between `x` and `y`.\n")
10224
0
SLANG_RAW("/// @remarks This function is equivalent to `length(x - y)`. When `x` and `y` are scalars, this function is equivalent to `abs(x - y)`.\n")
10225
0
SLANG_RAW("/// @category math\n")
10226
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10227
0
SLANG_RAW("[__readNone]\n")
10228
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10229
0
SLANG_RAW("T distance(vector<T, N> x, vector<T, N> y)\n")
10230
0
SLANG_RAW("{\n")
10231
0
SLANG_RAW("    __target_switch\n")
10232
0
SLANG_RAW("    {\n")
10233
0
SLANG_RAW("    case glsl: __intrinsic_asm \"distance\";\n")
10234
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"distance\";\n")
10235
0
SLANG_RAW("    case metal: __intrinsic_asm \"distance\";\n")
10236
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10237
0
SLANG_RAW("        OpExtInst $$T result glsl450 Distance $x $y\n")
10238
0
SLANG_RAW("    };\n")
10239
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"distance\";\n")
10240
0
SLANG_RAW("    default:\n")
10241
0
SLANG_RAW("        return length(x - y);\n")
10242
0
SLANG_RAW("    }\n")
10243
0
SLANG_RAW("}\n")
10244
0
SLANG_RAW("\n")
10245
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10246
0
SLANG_RAW("[__readNone]\n")
10247
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10248
0
SLANG_RAW("T distance(T x, T y)\n")
10249
0
SLANG_RAW("{\n")
10250
0
SLANG_RAW("    __target_switch\n")
10251
0
SLANG_RAW("    {\n")
10252
0
SLANG_RAW("    case glsl: __intrinsic_asm \"distance\";\n")
10253
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10254
0
SLANG_RAW("        OpExtInst $$T result glsl450 Distance $x $y\n")
10255
0
SLANG_RAW("    };\n")
10256
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"distance\";\n")
10257
0
SLANG_RAW("    default:\n")
10258
0
SLANG_RAW("        return length(x - y);\n")
10259
0
SLANG_RAW("    }\n")
10260
0
SLANG_RAW("}\n")
10261
0
SLANG_RAW("\n")
10262
0
SLANG_RAW("/// Computes `max(0, x-y)`.\n")
10263
0
SLANG_RAW("/// @param x The first value.\n")
10264
0
SLANG_RAW("/// @param y The second value.\n")
10265
0
SLANG_RAW("/// @return The result of `max(0, x-y)`.\n")
10266
0
SLANG_RAW("/// @category math\n")
10267
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10268
0
SLANG_RAW("[__readNone]\n")
10269
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
10270
0
SLANG_RAW("T fdim(T x, T y)\n")
10271
0
SLANG_RAW("{\n")
10272
0
SLANG_RAW("    __target_switch\n")
10273
0
SLANG_RAW("    {\n")
10274
0
SLANG_RAW("    case metal: __intrinsic_asm \"fdim\";\n")
10275
0
SLANG_RAW("    default:\n")
10276
0
SLANG_RAW("        return max(T(0), x - y);\n")
10277
0
SLANG_RAW("    }\n")
10278
0
SLANG_RAW("}\n")
10279
0
SLANG_RAW("\n")
10280
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10281
0
SLANG_RAW("[__readNone]\n")
10282
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
10283
0
SLANG_RAW("vector<T,N> fdim(vector<T,N> x, vector<T,N> y)\n")
10284
0
SLANG_RAW("{\n")
10285
0
SLANG_RAW("    __target_switch\n")
10286
0
SLANG_RAW("    {\n")
10287
0
SLANG_RAW("    case metal: __intrinsic_asm \"fdim\";\n")
10288
0
SLANG_RAW("    default:\n")
10289
0
SLANG_RAW("        return max(T(0), x - y);\n")
10290
0
SLANG_RAW("    }\n")
10291
0
SLANG_RAW("}\n")
10292
0
SLANG_RAW("\n")
10293
0
SLANG_RAW("/// Divide values.\n")
10294
0
SLANG_RAW("/// @param x The dividend.\n")
10295
0
SLANG_RAW("/// @param y The divisor.\n")
10296
0
SLANG_RAW("/// @return The result of dividing `x` by `y`, element-wise for vector types.\n")
10297
0
SLANG_RAW("/// @category math\n")
10298
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10299
0
SLANG_RAW("[__readNone]\n")
10300
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10301
0
SLANG_RAW("T divide(T x, T y)\n")
10302
0
SLANG_RAW("{\n")
10303
0
SLANG_RAW("    __target_switch\n")
10304
0
SLANG_RAW("    {\n")
10305
0
SLANG_RAW("    case metal: __intrinsic_asm \"divide\";\n")
10306
0
SLANG_RAW("    default:\n")
10307
0
SLANG_RAW("        return x / y;\n")
10308
0
SLANG_RAW("    }\n")
10309
0
SLANG_RAW("}\n")
10310
0
SLANG_RAW("\n")
10311
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
10312
0
SLANG_RAW("[__readNone]\n")
10313
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl)]\n")
10314
0
SLANG_RAW("vector<T,N> divide(vector<T,N> x, vector<T,N> y)\n")
10315
0
SLANG_RAW("{\n")
10316
0
SLANG_RAW("    __target_switch\n")
10317
0
SLANG_RAW("    {\n")
10318
0
SLANG_RAW("    case metal: __intrinsic_asm \"divide\";\n")
10319
0
SLANG_RAW("    default:\n")
10320
0
SLANG_RAW("        return x / y;\n")
10321
0
SLANG_RAW("    }\n")
10322
0
SLANG_RAW("}\n")
10323
0
SLANG_RAW("\n")
10324
0
SLANG_RAW("/// Vector dot product. Returns the dot product of two vectors.\n")
10325
0
SLANG_RAW("/// @param x The first vector.\n")
10326
0
SLANG_RAW("/// @param y The second vector.\n")
10327
0
SLANG_RAW("/// @return The dot product of `x` and `y`.\n")
10328
0
SLANG_RAW("/// @remarks When `x` and `y` are scalars, this function is equivalent to `x * y`.\n")
10329
0
SLANG_RAW("/// @category math\n")
10330
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10331
0
SLANG_RAW("[__readNone]\n")
10332
0
SLANG_RAW("[ForceInline]\n")
10333
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10334
0
SLANG_RAW("T dot(T x, T y)\n")
10335
0
SLANG_RAW("{\n")
10336
0
SLANG_RAW("    __target_switch\n")
10337
0
SLANG_RAW("    {\n")
10338
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dot\";\n")
10339
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot\";\n")
10340
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"dot\";\n")
10341
0
SLANG_RAW("    default:\n")
10342
0
SLANG_RAW("        return x * y;\n")
10343
0
SLANG_RAW("    }\n")
10344
0
SLANG_RAW("}\n")
10345
0
SLANG_RAW("\n")
10346
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10347
0
SLANG_RAW("[__readNone]\n")
10348
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10349
0
SLANG_RAW("T dot(vector<T, N> x, vector<T, N> y)\n")
10350
0
SLANG_RAW("{\n")
10351
0
SLANG_RAW("    // Handle 1-vector case explicitly since many backends don't support it natively\n")
10352
0
SLANG_RAW("    if (N == 1)\n")
10353
0
SLANG_RAW("    {\n")
10354
0
SLANG_RAW("        return x[0] * y[0];\n")
10355
0
SLANG_RAW("    }\n")
10356
0
SLANG_RAW("    \n")
10357
0
SLANG_RAW("    __target_switch\n")
10358
0
SLANG_RAW("    {\n")
10359
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dot\";\n")
10360
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot\";\n")
10361
0
SLANG_RAW("    case metal: __intrinsic_asm \"dot\";\n")
10362
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10363
0
SLANG_RAW("        OpDot $$T result $x $y\n")
10364
0
SLANG_RAW("    };\n")
10365
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"dot\";\n")
10366
0
SLANG_RAW("    default:\n")
10367
0
SLANG_RAW("        T result = T(0);\n")
10368
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
10369
0
SLANG_RAW("            result += x[i] * y[i];\n")
10370
0
SLANG_RAW("        return result;\n")
10371
0
SLANG_RAW("    }\n")
10372
0
SLANG_RAW("}\n")
10373
0
SLANG_RAW("\n")
10374
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
10375
0
SLANG_RAW("[__readNone]\n")
10376
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10377
0
SLANG_RAW("T dot(vector<T, N> x, vector<T, N> y)\n")
10378
0
SLANG_RAW("{\n")
10379
0
SLANG_RAW("    // Handle 1-vector case explicitly since many backends don't support it natively\n")
10380
0
SLANG_RAW("    if (N == 1)\n")
10381
0
SLANG_RAW("    {\n")
10382
0
SLANG_RAW("        return x[0] * y[0];\n")
10383
0
SLANG_RAW("    }\n")
10384
0
SLANG_RAW("    \n")
10385
0
SLANG_RAW("    __target_switch\n")
10386
0
SLANG_RAW("    {\n")
10387
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot\";\n")
10388
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"dot\";\n")
10389
0
SLANG_RAW("    case spirv:\n")
10390
0
SLANG_RAW("    {\n")
10391
0
SLANG_RAW("        spirv_asm\n")
10392
0
SLANG_RAW("        {\n")
10393
0
SLANG_RAW("            OpCapability DotProduct;\n")
10394
0
SLANG_RAW("            OpCapability DotProductInputAll;\n")
10395
0
SLANG_RAW("            OpExtension \"SPV_KHR_integer_dot_product\";\n")
10396
0
SLANG_RAW("        };\n")
10397
0
SLANG_RAW("\n")
10398
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
10399
0
SLANG_RAW("        {\n")
10400
0
SLANG_RAW("            return spirv_asm\n")
10401
0
SLANG_RAW("            {\n")
10402
0
SLANG_RAW("                result:$$T = OpSDot $x $y;\n")
10403
0
SLANG_RAW("            };\n")
10404
0
SLANG_RAW("        }\n")
10405
0
SLANG_RAW("        else\n")
10406
0
SLANG_RAW("        {\n")
10407
0
SLANG_RAW("            return spirv_asm\n")
10408
0
SLANG_RAW("            {\n")
10409
0
SLANG_RAW("                result:$$T = OpUDot $x $y;\n")
10410
0
SLANG_RAW("            };\n")
10411
0
SLANG_RAW("        }\n")
10412
0
SLANG_RAW("    }\n")
10413
0
SLANG_RAW("    default:\n")
10414
0
SLANG_RAW("        T result = T(0);\n")
10415
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
10416
0
SLANG_RAW("            result += x[i] * y[i];\n")
10417
0
SLANG_RAW("        return result;\n")
10418
0
SLANG_RAW("    }\n")
10419
0
SLANG_RAW("}\n")
10420
0
SLANG_RAW("\n")
10421
0
SLANG_RAW("/// Helper for computing distance terms for lighting (obsolete).\n")
10422
0
SLANG_RAW("/// Use the subtraction operator '-' instead.\n")
10423
0
SLANG_RAW("/// @deprecated\n")
10424
0
SLANG_RAW("/// @category math\n")
10425
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType> vector<T,4> dst(vector<T,4> x, vector<T,4> y);\n")
10426
0
SLANG_RAW("\n")
10427
0
SLANG_RAW("// Given a RWByteAddressBuffer allow it to be interpreted as a RWStructuredBuffer\n")
10428
0
SLANG_RAW("__intrinsic_op(")
10429
0
SLANG_SPLICE(kIROp_GetEquivalentStructuredBuffer
10430
0
)
10431
0
SLANG_RAW(")\n")
10432
0
SLANG_RAW("RWStructuredBuffer<T> __getEquivalentStructuredBuffer<T>(RWByteAddressBuffer b);\n")
10433
0
SLANG_RAW("\n")
10434
0
SLANG_RAW("__intrinsic_op(")
10435
0
SLANG_SPLICE(kIROp_GetEquivalentStructuredBuffer
10436
0
)
10437
0
SLANG_RAW(")\n")
10438
0
SLANG_RAW("StructuredBuffer<T> __getEquivalentStructuredBuffer<T>(ByteAddressBuffer b);\n")
10439
0
SLANG_RAW("\n")
10440
0
SLANG_RAW("__intrinsic_op(")
10441
0
SLANG_SPLICE(kIROp_GetEquivalentStructuredBuffer
10442
0
)
10443
0
SLANG_RAW(")\n")
10444
0
SLANG_RAW("RasterizerOrderedStructuredBuffer<T> __getEquivalentStructuredBuffer<T>(RasterizerOrderedByteAddressBuffer b);\n")
10445
0
SLANG_RAW("\n")
10446
0
SLANG_RAW("// Error message\n")
10447
0
SLANG_RAW("\n")
10448
0
SLANG_RAW("// void errorf( string format, ... );\n")
10449
0
SLANG_RAW("\n")
10450
0
SLANG_RAW("// Attribute evaluation\n")
10451
0
SLANG_RAW("\n")
10452
0
SLANG_RAW("T __EvaluateAttributeAtCentroid<T>(__constref T x)\n")
10453
0
SLANG_RAW("{\n")
10454
0
SLANG_RAW("    __target_switch\n")
10455
0
SLANG_RAW("    {\n")
10456
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"EvaluateAttributeAtCentroid\";\n")
10457
0
SLANG_RAW("    case glsl: __intrinsic_asm \"interpolateAtCentroid\";\n")
10458
0
SLANG_RAW("    }\n")
10459
0
SLANG_RAW("}\n")
10460
0
SLANG_RAW("\n")
10461
0
SLANG_RAW("// TODO: The matrix cases of these functions won't actuall work\n")
10462
0
SLANG_RAW("// when compiled to GLSL, since they only support scalar/vector\n")
10463
0
SLANG_RAW("\n")
10464
0
SLANG_RAW("// TODO: Should these be constrains to `__BuiltinFloatingPointType`?\n")
10465
0
SLANG_RAW("// TODO: SPIRV-direct does not support non-floating-point types.\n")
10466
0
SLANG_RAW("\n")
10467
0
SLANG_RAW("/// Interpolates vertex attribute at centroid position.\n")
10468
0
SLANG_RAW("/// @param x The vertex attribute to interpolate.\n")
10469
0
SLANG_RAW("/// @return The interpolated attribute value.\n")
10470
0
SLANG_RAW("/// @remarks `x` must be a direct reference to a fragment shader varying input.\n")
10471
0
SLANG_RAW("/// @category interpolation Vertex Interpolation Functions\n")
10472
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
10473
0
SLANG_RAW("[__readNone]\n")
10474
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10475
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10476
0
SLANG_RAW("T EvaluateAttributeAtCentroid(__constref T x)\n")
10477
0
SLANG_RAW("{\n")
10478
0
SLANG_RAW("    __target_switch\n")
10479
0
SLANG_RAW("    {\n")
10480
0
SLANG_RAW("    case hlsl:\n")
10481
0
SLANG_RAW("    case glsl:\n")
10482
0
SLANG_RAW("        return __EvaluateAttributeAtCentroid(__ResolveVaryingInputRef(x));\n")
10483
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10484
0
SLANG_RAW("        OpCapability InterpolationFunction;\n")
10485
0
SLANG_RAW("        OpExtInst $$T result glsl450 InterpolateAtCentroid $__ResolveVaryingInputRef(x)\n")
10486
0
SLANG_RAW("    };\n")
10487
0
SLANG_RAW("    }\n")
10488
0
SLANG_RAW("}\n")
10489
0
SLANG_RAW("\n")
10490
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
10491
0
SLANG_RAW("[__readNone]\n")
10492
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10493
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10494
0
SLANG_RAW("vector<T,N> EvaluateAttributeAtCentroid(__constref vector<T,N> x)\n")
10495
0
SLANG_RAW("{\n")
10496
0
SLANG_RAW("    __target_switch\n")
10497
0
SLANG_RAW("    {\n")
10498
0
SLANG_RAW("    case hlsl:\n")
10499
0
SLANG_RAW("    case glsl:\n")
10500
0
SLANG_RAW("        return __EvaluateAttributeAtCentroid(__ResolveVaryingInputRef(x));\n")
10501
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10502
0
SLANG_RAW("        OpCapability InterpolationFunction;\n")
10503
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 InterpolateAtCentroid $__ResolveVaryingInputRef(x)\n")
10504
0
SLANG_RAW("    };\n")
10505
0
SLANG_RAW("    }\n")
10506
0
SLANG_RAW("}\n")
10507
0
SLANG_RAW("\n")
10508
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
10509
0
SLANG_RAW("[__readNone]\n")
10510
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10511
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10512
0
SLANG_RAW("matrix<T,N,M> EvaluateAttributeAtCentroid(__constref matrix<T,N,M> x)\n")
10513
0
SLANG_RAW("{\n")
10514
0
SLANG_RAW("    __target_switch\n")
10515
0
SLANG_RAW("    {\n")
10516
0
SLANG_RAW("    case hlsl:\n")
10517
0
SLANG_RAW("    case glsl:\n")
10518
0
SLANG_RAW("        return __EvaluateAttributeAtCentroid(__ResolveVaryingInputRef(x));\n")
10519
0
SLANG_RAW("    default:\n")
10520
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, EvaluateAttributeAtCentroid, x);\n")
10521
0
SLANG_RAW("    }\n")
10522
0
SLANG_RAW("}\n")
10523
0
SLANG_RAW("\n")
10524
0
SLANG_RAW("T __EvaluateAttributeAtSample<T>(__constref T x, uint sampleIndex)\n")
10525
0
SLANG_RAW("{\n")
10526
0
SLANG_RAW("    __target_switch\n")
10527
0
SLANG_RAW("    {\n")
10528
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"EvaluateAttributeAtSample\";\n")
10529
0
SLANG_RAW("    case glsl: __intrinsic_asm \"interpolateAtSample\";\n")
10530
0
SLANG_RAW("    }\n")
10531
0
SLANG_RAW("}\n")
10532
0
SLANG_RAW("\n")
10533
0
SLANG_RAW("/// Interpolates vertex attribute at the current fragment sample position.\n")
10534
0
SLANG_RAW("/// @param x The vertex attribute to interpolate.\n")
10535
0
SLANG_RAW("/// @return The interpolated attribute value.\n")
10536
0
SLANG_RAW("/// @remarks `x` must be a direct reference to a fragment shader varying input.\n")
10537
0
SLANG_RAW("/// @category interpolation Vertex Interpolation Functions\n")
10538
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
10539
0
SLANG_RAW("[__readNone]\n")
10540
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10541
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10542
0
SLANG_RAW("T EvaluateAttributeAtSample(__constref T x, uint sampleindex)\n")
10543
0
SLANG_RAW("{\n")
10544
0
SLANG_RAW("    __target_switch\n")
10545
0
SLANG_RAW("    {\n")
10546
0
SLANG_RAW("    case hlsl:\n")
10547
0
SLANG_RAW("    case glsl:\n")
10548
0
SLANG_RAW("        return __EvaluateAttributeAtSample(__ResolveVaryingInputRef(x), sampleindex);\n")
10549
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10550
0
SLANG_RAW("        OpCapability InterpolationFunction;\n")
10551
0
SLANG_RAW("        OpExtInst $$T result glsl450 InterpolateAtSample $__ResolveVaryingInputRef(x) $sampleindex\n")
10552
0
SLANG_RAW("    };\n")
10553
0
SLANG_RAW("    }\n")
10554
0
SLANG_RAW("}\n")
10555
0
SLANG_RAW("\n")
10556
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
10557
0
SLANG_RAW("[__readNone]\n")
10558
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10559
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10560
0
SLANG_RAW("vector<T,N> EvaluateAttributeAtSample(__constref vector<T,N> x, uint sampleindex)\n")
10561
0
SLANG_RAW("{\n")
10562
0
SLANG_RAW("    __target_switch\n")
10563
0
SLANG_RAW("    {\n")
10564
0
SLANG_RAW("    case hlsl:\n")
10565
0
SLANG_RAW("    case glsl:\n")
10566
0
SLANG_RAW("        return __EvaluateAttributeAtSample(__ResolveVaryingInputRef(x), sampleindex);\n")
10567
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10568
0
SLANG_RAW("        OpCapability InterpolationFunction;\n")
10569
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 InterpolateAtSample $__ResolveVaryingInputRef(x) $sampleindex\n")
10570
0
SLANG_RAW("    };\n")
10571
0
SLANG_RAW("    }\n")
10572
0
SLANG_RAW("}\n")
10573
0
SLANG_RAW("\n")
10574
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
10575
0
SLANG_RAW("[__readNone]\n")
10576
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10577
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10578
0
SLANG_RAW("matrix<T,N,M> EvaluateAttributeAtSample(__constref matrix<T,N,M> x, uint sampleindex)\n")
10579
0
SLANG_RAW("{\n")
10580
0
SLANG_RAW("    __target_switch\n")
10581
0
SLANG_RAW("    {\n")
10582
0
SLANG_RAW("    case hlsl:\n")
10583
0
SLANG_RAW("    case glsl:\n")
10584
0
SLANG_RAW("        return __EvaluateAttributeAtSample(__ResolveVaryingInputRef(x), sampleindex);\n")
10585
0
SLANG_RAW("    default:\n")
10586
0
SLANG_RAW("        matrix<T,N,M> result;\n")
10587
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
10588
0
SLANG_RAW("        {\n")
10589
0
SLANG_RAW("            result[i] = EvaluateAttributeAtSample(x[i], sampleindex);\n")
10590
0
SLANG_RAW("        }\n")
10591
0
SLANG_RAW("        return result;\n")
10592
0
SLANG_RAW("    }\n")
10593
0
SLANG_RAW("}\n")
10594
0
SLANG_RAW("\n")
10595
0
SLANG_RAW("T __EvaluateAttributeSnapped<T>(__constref T x, int2 offset)\n")
10596
0
SLANG_RAW("{\n")
10597
0
SLANG_RAW("    __target_switch\n")
10598
0
SLANG_RAW("    {\n")
10599
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"EvaluateAttributeSnapped\";\n")
10600
0
SLANG_RAW("    case glsl: __intrinsic_asm \"EvaluateAttributeSnapped\";\n")
10601
0
SLANG_RAW("    }\n")
10602
0
SLANG_RAW("}\n")
10603
0
SLANG_RAW("\n")
10604
0
SLANG_RAW("/// Interpolates vertex attribute at the specified subpixel offset.\n")
10605
0
SLANG_RAW("/// @param x The vertex attribute to interpolate.\n")
10606
0
SLANG_RAW("/// @param offset The subpixel offset. Each component is a 4-bit signed integer in range [-8, 7].\n")
10607
0
SLANG_RAW("/// @return The interpolated attribute value.\n")
10608
0
SLANG_RAW("/// @remarks `x` must be a direct reference to a fragment shader varying input.\n")
10609
0
SLANG_RAW("///\n")
10610
0
SLANG_RAW("/// The valid values of each component of `offset` are:\n")
10611
0
SLANG_RAW("///\n")
10612
0
SLANG_RAW("/// - 1000 = -0.5f (-8 / 16)\n")
10613
0
SLANG_RAW("/// - 1001 = -0.4375f (-7 / 16)\n")
10614
0
SLANG_RAW("/// - 1010 = -0.375f (-6 / 16)\n")
10615
0
SLANG_RAW("/// - 1011 = -0.3125f (-5 / 16)\n")
10616
0
SLANG_RAW("/// - 1100 = -0.25f (-4 / 16)\n")
10617
0
SLANG_RAW("/// - 1101 = -0.1875f (-3 / 16)\n")
10618
0
SLANG_RAW("/// - 1110 = -0.125f (-2 / 16)\n")
10619
0
SLANG_RAW("/// - 1111 = -0.0625f (-1 / 16)\n")
10620
0
SLANG_RAW("/// - 0000 = 0.0f ( 0 / 16)\n")
10621
0
SLANG_RAW("/// - 0001 = 0.0625f ( 1 / 16)\n")
10622
0
SLANG_RAW("/// - 0010 = 0.125f ( 2 / 16)\n")
10623
0
SLANG_RAW("/// - 0011 = 0.1875f ( 3 / 16)\n")
10624
0
SLANG_RAW("/// - 0100 = 0.25f ( 4 / 16)\n")
10625
0
SLANG_RAW("/// - 0101 = 0.3125f ( 5 / 16)\n")
10626
0
SLANG_RAW("/// - 0110 = 0.375f ( 6 / 16)\n")
10627
0
SLANG_RAW("/// - 0111 = 0.4375f ( 7 / 16)\n")
10628
0
SLANG_RAW("/// @category interpolation Vertex Interpolation Functions\n")
10629
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
10630
0
SLANG_RAW("[__readNone]\n")
10631
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10632
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10633
0
SLANG_RAW("T EvaluateAttributeSnapped(__constref T x, int2 offset)\n")
10634
0
SLANG_RAW("{\n")
10635
0
SLANG_RAW("    __target_switch\n")
10636
0
SLANG_RAW("    {\n")
10637
0
SLANG_RAW("    case hlsl:\n")
10638
0
SLANG_RAW("    case glsl:\n")
10639
0
SLANG_RAW("        return __EvaluateAttributeSnapped(__ResolveVaryingInputRef(x), offset);\n")
10640
0
SLANG_RAW("    case spirv:\n")
10641
0
SLANG_RAW("    {\n")
10642
0
SLANG_RAW("        const float2 tmp = float2(16.f, 16.f);\n")
10643
0
SLANG_RAW("        return spirv_asm {\n")
10644
0
SLANG_RAW("            OpCapability InterpolationFunction;\n")
10645
0
SLANG_RAW("            %foffset:$$float2 = OpConvertSToF $offset;\n")
10646
0
SLANG_RAW("            %offsetdiv16:$$float2 = OpFDiv %foffset $tmp;\n")
10647
0
SLANG_RAW("            result:$$T = OpExtInst glsl450 InterpolateAtOffset $__ResolveVaryingInputRef(x) %offsetdiv16\n")
10648
0
SLANG_RAW("        };\n")
10649
0
SLANG_RAW("    }\n")
10650
0
SLANG_RAW("    }\n")
10651
0
SLANG_RAW("}\n")
10652
0
SLANG_RAW("\n")
10653
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
10654
0
SLANG_RAW("[__readNone]\n")
10655
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10656
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10657
0
SLANG_RAW("vector<T,N> EvaluateAttributeSnapped(__constref vector<T,N> x, int2 offset)\n")
10658
0
SLANG_RAW("{\n")
10659
0
SLANG_RAW("    __target_switch\n")
10660
0
SLANG_RAW("    {\n")
10661
0
SLANG_RAW("    case hlsl:\n")
10662
0
SLANG_RAW("    case glsl:\n")
10663
0
SLANG_RAW("        return __EvaluateAttributeSnapped(__ResolveVaryingInputRef(x), offset);\n")
10664
0
SLANG_RAW("    case spirv:\n")
10665
0
SLANG_RAW("    {\n")
10666
0
SLANG_RAW("        const float2 tmp = float2(16.f, 16.f);\n")
10667
0
SLANG_RAW("        return spirv_asm {\n")
10668
0
SLANG_RAW("            OpCapability InterpolationFunction;\n")
10669
0
SLANG_RAW("            %foffset:$$float2 = OpConvertSToF $offset;\n")
10670
0
SLANG_RAW("            %offsetdiv16:$$float2 = OpFDiv %foffset $tmp;\n")
10671
0
SLANG_RAW("            result:$$vector<T,N> = OpExtInst glsl450 InterpolateAtOffset $__ResolveVaryingInputRef(x) %offsetdiv16\n")
10672
0
SLANG_RAW("        };\n")
10673
0
SLANG_RAW("    }\n")
10674
0
SLANG_RAW("    }\n")
10675
0
SLANG_RAW("}\n")
10676
0
SLANG_RAW("\n")
10677
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
10678
0
SLANG_RAW("[__readNone]\n")
10679
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
10680
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
10681
0
SLANG_RAW("matrix<T,N,M> EvaluateAttributeSnapped(__constref matrix<T,N,M> x, int2 offset)\n")
10682
0
SLANG_RAW("{\n")
10683
0
SLANG_RAW("    __target_switch\n")
10684
0
SLANG_RAW("    {\n")
10685
0
SLANG_RAW("    case hlsl:\n")
10686
0
SLANG_RAW("    case glsl:\n")
10687
0
SLANG_RAW("        return __EvaluateAttributeSnapped(__ResolveVaryingInputRef(x), offset);\n")
10688
0
SLANG_RAW("    default:\n")
10689
0
SLANG_RAW("        matrix<T,N,M> result;\n")
10690
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
10691
0
SLANG_RAW("        {\n")
10692
0
SLANG_RAW("            result[i] = EvaluateAttributeSnapped(x[i], offset);\n")
10693
0
SLANG_RAW("        }\n")
10694
0
SLANG_RAW("        return result;\n")
10695
0
SLANG_RAW("    }\n")
10696
0
SLANG_RAW("}\n")
10697
0
SLANG_RAW("\n")
10698
0
SLANG_RAW("/// Computes base-e exponent.\n")
10699
0
SLANG_RAW("/// @param x The input value.\n")
10700
0
SLANG_RAW("/// @return The base-e exponent of `x`.\n")
10701
0
SLANG_RAW("/// @category math\n")
10702
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10703
0
SLANG_RAW("[__readNone]\n")
10704
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10705
0
SLANG_RAW("T exp(T x)\n")
10706
0
SLANG_RAW("{\n")
10707
0
SLANG_RAW("    __target_switch\n")
10708
0
SLANG_RAW("    {\n")
10709
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_exp($0)\";\n")
10710
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_exp($0)\";\n")
10711
0
SLANG_RAW("    case glsl: __intrinsic_asm \"exp\";\n")
10712
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"exp\";\n")
10713
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp\";\n")
10714
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10715
0
SLANG_RAW("        OpExtInst $$T result glsl450 Exp $x\n")
10716
0
SLANG_RAW("    };\n")
10717
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"exp\";\n")
10718
0
SLANG_RAW("    }\n")
10719
0
SLANG_RAW("}\n")
10720
0
SLANG_RAW("\n")
10721
0
SLANG_RAW("/// @category math\n")
10722
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10723
0
SLANG_RAW("[__readNone]\n")
10724
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10725
0
SLANG_RAW("vector<T, N> exp(vector<T, N> x)\n")
10726
0
SLANG_RAW("{\n")
10727
0
SLANG_RAW("    __target_switch\n")
10728
0
SLANG_RAW("    {\n")
10729
0
SLANG_RAW("    case glsl: __intrinsic_asm \"exp\";\n")
10730
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"exp\";\n")
10731
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp\";\n")
10732
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10733
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Exp $x\n")
10734
0
SLANG_RAW("    };\n")
10735
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"exp\";\n")
10736
0
SLANG_RAW("    default:\n")
10737
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, exp, x);\n")
10738
0
SLANG_RAW("    }\n")
10739
0
SLANG_RAW("}\n")
10740
0
SLANG_RAW("\n")
10741
0
SLANG_RAW("/// @category math\n")
10742
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
10743
0
SLANG_RAW("[__readNone]\n")
10744
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10745
0
SLANG_RAW("matrix<T, N, M> exp(matrix<T, N, M> x)\n")
10746
0
SLANG_RAW("{\n")
10747
0
SLANG_RAW("    __target_switch\n")
10748
0
SLANG_RAW("    {\n")
10749
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"exp\";\n")
10750
0
SLANG_RAW("    default:\n")
10751
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, exp, x);\n")
10752
0
SLANG_RAW("    }\n")
10753
0
SLANG_RAW("}\n")
10754
0
SLANG_RAW("\n")
10755
0
SLANG_RAW("/// Computes base-2 exponent.\n")
10756
0
SLANG_RAW("/// @param x The input value.\n")
10757
0
SLANG_RAW("/// @return The base-2 exponent of `x`.\n")
10758
0
SLANG_RAW("/// @category math\n")
10759
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10760
0
SLANG_RAW("[__readNone]\n")
10761
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10762
0
SLANG_RAW("T exp2(T x)\n")
10763
0
SLANG_RAW("{\n")
10764
0
SLANG_RAW("    __target_switch\n")
10765
0
SLANG_RAW("    {\n")
10766
0
SLANG_RAW("    case glsl:\n")
10767
0
SLANG_RAW("        __intrinsic_asm \"exp2($0)\";\n")
10768
0
SLANG_RAW("    case spirv:\n")
10769
0
SLANG_RAW("        if (__isHalf<T>())\n")
10770
0
SLANG_RAW("        {\n")
10771
0
SLANG_RAW("            return spirv_asm { OpExtInst $$T result glsl450 Exp2 $x };\n")
10772
0
SLANG_RAW("        }\n")
10773
0
SLANG_RAW("        else\n")
10774
0
SLANG_RAW("        {\n")
10775
0
SLANG_RAW("            float xf = __realCast<float>(x);\n")
10776
0
SLANG_RAW("            return T(spirv_asm {\n")
10777
0
SLANG_RAW("                 result:$$float = OpExtInst glsl450 Exp2 $xf\n")
10778
0
SLANG_RAW("            });\n")
10779
0
SLANG_RAW("        }\n")
10780
0
SLANG_RAW("    case hlsl:\n")
10781
0
SLANG_RAW("        __intrinsic_asm \"exp2($0)\";\n")
10782
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp2\";\n")
10783
0
SLANG_RAW("    case cpp:\n")
10784
0
SLANG_RAW("        __intrinsic_asm \"$P_exp2($0)\";\n")
10785
0
SLANG_RAW("    case cuda:\n")
10786
0
SLANG_RAW("        __intrinsic_asm \"$P_exp2($0)\";\n")
10787
0
SLANG_RAW("    case wgsl:\n")
10788
0
SLANG_RAW("        __intrinsic_asm \"exp2\";\n")
10789
0
SLANG_RAW("    }\n")
10790
0
SLANG_RAW("\n")
10791
0
SLANG_RAW("}\n")
10792
0
SLANG_RAW("\n")
10793
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
10794
0
SLANG_RAW("[__readNone]\n")
10795
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10796
0
SLANG_RAW("vector<T,N> exp2(vector<T,N> x)\n")
10797
0
SLANG_RAW("{\n")
10798
0
SLANG_RAW("    __target_switch\n")
10799
0
SLANG_RAW("    {\n")
10800
0
SLANG_RAW("    case glsl:\n")
10801
0
SLANG_RAW("        __intrinsic_asm \"exp2($0)\";\n")
10802
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"exp2\";\n")
10803
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp2\";\n")
10804
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
10805
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Exp2 $x\n")
10806
0
SLANG_RAW("    };\n")
10807
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"exp2\";\n")
10808
0
SLANG_RAW("    default:\n")
10809
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, exp2, x);\n")
10810
0
SLANG_RAW("    }\n")
10811
0
SLANG_RAW("}\n")
10812
0
SLANG_RAW("\n")
10813
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
10814
0
SLANG_RAW("[__readNone]\n")
10815
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10816
0
SLANG_RAW("matrix<T,N,M> exp2(matrix<T,N,M> x)\n")
10817
0
SLANG_RAW("{\n")
10818
0
SLANG_RAW("    __target_switch\n")
10819
0
SLANG_RAW("    {\n")
10820
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"exp2\";\n")
10821
0
SLANG_RAW("    default:\n")
10822
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, exp2, x);\n")
10823
0
SLANG_RAW("    }\n")
10824
0
SLANG_RAW("}\n")
10825
0
SLANG_RAW("\n")
10826
0
SLANG_RAW("/// Computes base-10 exponent.\n")
10827
0
SLANG_RAW("/// @param x The input value.\n")
10828
0
SLANG_RAW("/// @return The base-10 exponent of `x`.\n")
10829
0
SLANG_RAW("/// @category math\n")
10830
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
10831
0
SLANG_RAW("[__readNone]\n")
10832
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10833
0
SLANG_RAW("T exp10(T x)\n")
10834
0
SLANG_RAW("{\n")
10835
0
SLANG_RAW("    __target_switch\n")
10836
0
SLANG_RAW("    {\n")
10837
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp10\";\n")
10838
0
SLANG_RAW("    default:\n")
10839
0
SLANG_RAW("        const T ln10 = T(2.302585092994045901); // ln(10)\n")
10840
0
SLANG_RAW("        return exp(x * ln10);\n")
10841
0
SLANG_RAW("    }\n")
10842
0
SLANG_RAW("}\n")
10843
0
SLANG_RAW("\n")
10844
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
10845
0
SLANG_RAW("[__readNone]\n")
10846
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10847
0
SLANG_RAW("vector<T,N> exp10(vector<T,N> x)\n")
10848
0
SLANG_RAW("{\n")
10849
0
SLANG_RAW("    __target_switch\n")
10850
0
SLANG_RAW("    {\n")
10851
0
SLANG_RAW("    case metal: __intrinsic_asm \"exp10\";\n")
10852
0
SLANG_RAW("    default:\n")
10853
0
SLANG_RAW("        const T ln10 = T(2.30258509299); // ln(10)\n")
10854
0
SLANG_RAW("        return exp(x * ln10);\n")
10855
0
SLANG_RAW("    }\n")
10856
0
SLANG_RAW("}\n")
10857
0
SLANG_RAW("\n")
10858
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
10859
0
SLANG_RAW("[__readNone]\n")
10860
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
10861
0
SLANG_RAW("matrix<T,N,M> exp10(matrix<T,N,M> x)\n")
10862
0
SLANG_RAW("{\n")
10863
0
SLANG_RAW("    __target_switch\n")
10864
0
SLANG_RAW("    {\n")
10865
0
SLANG_RAW("    default:\n")
10866
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, exp10, x);\n")
10867
0
SLANG_RAW("    }\n")
10868
0
SLANG_RAW("}\n")
10869
0
SLANG_RAW("\n")
10870
0
SLANG_RAW("\n")
10871
0
SLANG_RAW("/// Convert 16-bit float stored in low bits of integer\n")
10872
0
SLANG_RAW("/// @category conversion Conversion functions\n")
10873
0
SLANG_RAW("__glsl_version(420)\n")
10874
0
SLANG_RAW("__cuda_sm_version(6.0)\n")
10875
0
SLANG_RAW("[__readNone]\n")
10876
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10877
0
SLANG_RAW("float f16tof32(uint value)\n")
10878
0
SLANG_RAW("{\n")
10879
0
SLANG_RAW("    __target_switch\n")
10880
0
SLANG_RAW("    {\n")
10881
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackHalf2x16($0).x\";\n")
10882
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f16tof32($0)\";\n")
10883
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half2float(__ushort_as_half($0))\";\n")
10884
0
SLANG_RAW("    case cpp: __intrinsic_asm \"f16tof32($0)\";\n")
10885
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<half>((ushort)($0))\";\n")
10886
0
SLANG_RAW("    case spirv:\n")
10887
0
SLANG_RAW("    {\n")
10888
0
SLANG_RAW("        return spirv_asm {\n")
10889
0
SLANG_RAW("            %lowBits = OpUConvert $$uint16_t $value;\n")
10890
0
SLANG_RAW("            %half = OpBitcast $$half %lowBits;\n")
10891
0
SLANG_RAW("            result:$$float = OpFConvert %half\n")
10892
0
SLANG_RAW("        };\n")
10893
0
SLANG_RAW("    }\n")
10894
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack2x16float($0).x\";\n")
10895
0
SLANG_RAW("    }\n")
10896
0
SLANG_RAW("}\n")
10897
0
SLANG_RAW("\n")
10898
0
SLANG_RAW("__generic<let N : int>\n")
10899
0
SLANG_RAW("[__readNone]\n")
10900
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10901
0
SLANG_RAW("vector<float, N> f16tof32(vector<uint, N> value)\n")
10902
0
SLANG_RAW("{\n")
10903
0
SLANG_RAW("    __target_switch\n")
10904
0
SLANG_RAW("    {\n")
10905
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f16tof32\";\n")
10906
0
SLANG_RAW("    case spirv:\n")
10907
0
SLANG_RAW("    {\n")
10908
0
SLANG_RAW("        return spirv_asm {\n")
10909
0
SLANG_RAW("            %lowBits = OpUConvert $$vector<uint16_t,N> $value;\n")
10910
0
SLANG_RAW("            %half = OpBitcast $$vector<half,N> %lowBits;\n")
10911
0
SLANG_RAW("            result:$$vector<float,N> = OpFConvert %half\n")
10912
0
SLANG_RAW("        };\n")
10913
0
SLANG_RAW("    }\n")
10914
0
SLANG_RAW("    default:\n")
10915
0
SLANG_RAW("        VECTOR_MAP_UNARY(float, N, f16tof32, value);\n")
10916
0
SLANG_RAW("    }\n")
10917
0
SLANG_RAW("}\n")
10918
0
SLANG_RAW("\n")
10919
0
SLANG_RAW("/// Convert to 16-bit float stored in low bits of integer.\n")
10920
0
SLANG_RAW("/// @category conversion\n")
10921
0
SLANG_RAW("__glsl_version(420)\n")
10922
0
SLANG_RAW("__cuda_sm_version(6.0)\n")
10923
0
SLANG_RAW("[__readNone]\n")
10924
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10925
0
SLANG_RAW("uint f32tof16(float value)\n")
10926
0
SLANG_RAW("{\n")
10927
0
SLANG_RAW("    __target_switch\n")
10928
0
SLANG_RAW("    {\n")
10929
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packHalf2x16(vec2($0,0.0))\";\n")
10930
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f32tof16($0)\";\n")
10931
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half_as_ushort(__float2half($0))\";\n")
10932
0
SLANG_RAW("    case cpp: __intrinsic_asm \"f32tof16($0)\";\n")
10933
0
SLANG_RAW("    case metal: __intrinsic_asm \"as_type<ushort>((half)($0))\";\n")
10934
0
SLANG_RAW("    case spirv:\n")
10935
0
SLANG_RAW("    {\n")
10936
0
SLANG_RAW("        return spirv_asm {\n")
10937
0
SLANG_RAW("            %half = OpFConvert $$half $value;\n")
10938
0
SLANG_RAW("            %lowBits = OpBitcast $$uint16_t %half;\n")
10939
0
SLANG_RAW("            result:$$uint = OpUConvert %lowBits\n")
10940
0
SLANG_RAW("        };\n")
10941
0
SLANG_RAW("    }\n")
10942
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack2x16float(vec2f($0,0.0))\";\n")
10943
0
SLANG_RAW("    }\n")
10944
0
SLANG_RAW("}\n")
10945
0
SLANG_RAW("\n")
10946
0
SLANG_RAW("__generic<let N : int>\n")
10947
0
SLANG_RAW("[__readNone]\n")
10948
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10949
0
SLANG_RAW("vector<uint, N> f32tof16(vector<float, N> value)\n")
10950
0
SLANG_RAW("{\n")
10951
0
SLANG_RAW("    __target_switch\n")
10952
0
SLANG_RAW("    {\n")
10953
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f32tof16\";\n")
10954
0
SLANG_RAW("    case spirv:\n")
10955
0
SLANG_RAW("    {\n")
10956
0
SLANG_RAW("        return spirv_asm {\n")
10957
0
SLANG_RAW("            %half = OpFConvert $$vector<half,N> $value;\n")
10958
0
SLANG_RAW("            %lowBits = OpBitcast $$vector<uint16_t,N> %half;\n")
10959
0
SLANG_RAW("            result:$$vector<uint,N> = OpUConvert %lowBits\n")
10960
0
SLANG_RAW("        };\n")
10961
0
SLANG_RAW("    }\n")
10962
0
SLANG_RAW("    default:\n")
10963
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, f32tof16, value);\n")
10964
0
SLANG_RAW("    }\n")
10965
0
SLANG_RAW("}\n")
10966
0
SLANG_RAW("\n")
10967
0
SLANG_RAW("// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
10968
0
SLANG_RAW("// The following is Slang specific and NOT part of standard HLSL\n")
10969
0
SLANG_RAW("// It's not clear what happens with float16 time in HLSL -> can the float16 coerce to uint for example? If so that would\n")
10970
0
SLANG_RAW("// give the wrong result\n")
10971
0
SLANG_RAW("\n")
10972
0
SLANG_RAW("__glsl_version(420)\n")
10973
0
SLANG_RAW("[__readNone]\n")
10974
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10975
0
SLANG_RAW("float f16tof32(float16_t value)\n")
10976
0
SLANG_RAW("{\n")
10977
0
SLANG_RAW("    __target_switch\n")
10978
0
SLANG_RAW("    {\n")
10979
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackHalf2x16($0).x\";\n")
10980
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f16tof32($0)\";\n")
10981
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half2float($0)\";\n")
10982
0
SLANG_RAW("    case cpp: __intrinsic_asm \"f16tof32($0)\";\n")
10983
0
SLANG_RAW("    case metal: __intrinsic_asm \"float($0)\";\n")
10984
0
SLANG_RAW("    case spirv:\n")
10985
0
SLANG_RAW("    {\n")
10986
0
SLANG_RAW("        return spirv_asm {\n")
10987
0
SLANG_RAW("            result:$$float = OpFConvert $value\n")
10988
0
SLANG_RAW("        };\n")
10989
0
SLANG_RAW("    }\n")
10990
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"f32($0)\";\n")
10991
0
SLANG_RAW("    }\n")
10992
0
SLANG_RAW("}\n")
10993
0
SLANG_RAW("\n")
10994
0
SLANG_RAW("__generic<let N : int>\n")
10995
0
SLANG_RAW("[__readNone]\n")
10996
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
10997
0
SLANG_RAW("vector<float, N> f16tof32(vector<float16_t, N> value)\n")
10998
0
SLANG_RAW("{\n")
10999
0
SLANG_RAW("    __target_switch\n")
11000
0
SLANG_RAW("    {\n")
11001
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__half2float\";\n")
11002
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"f16tof32\";\n")
11003
0
SLANG_RAW("    case metal: __intrinsic_asm \"$TR($0)\";\n")
11004
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11005
0
SLANG_RAW("        OpFConvert $$vector<float, N> result $value\n")
11006
0
SLANG_RAW("    };\n")
11007
0
SLANG_RAW("    default:\n")
11008
0
SLANG_RAW("        VECTOR_MAP_UNARY(float, N, f16tof32, value);\n")
11009
0
SLANG_RAW("    }\n")
11010
0
SLANG_RAW("}\n")
11011
0
SLANG_RAW("\n")
11012
0
SLANG_RAW("/// Convert to float16_t.\n")
11013
0
SLANG_RAW("/// @category conversion\n")
11014
0
SLANG_RAW("__glsl_version(420)\n")
11015
0
SLANG_RAW("[__readNone]\n")
11016
0
SLANG_RAW("[require(cuda_glsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11017
0
SLANG_RAW("float16_t f32tof16_(float value)\n")
11018
0
SLANG_RAW("{\n")
11019
0
SLANG_RAW("    __target_switch\n")
11020
0
SLANG_RAW("    {\n")
11021
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__float2half\";\n")
11022
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packHalf2x16(vec2($0,0.0))\";\n")
11023
0
SLANG_RAW("    case metal: __intrinsic_asm \"half($0)\";\n")
11024
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11025
0
SLANG_RAW("        OpFConvert $$float16_t result $value\n")
11026
0
SLANG_RAW("    };\n")
11027
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"f16($0)\";\n")
11028
0
SLANG_RAW("    }\n")
11029
0
SLANG_RAW("}\n")
11030
0
SLANG_RAW("\n")
11031
0
SLANG_RAW("__generic<let N : int>\n")
11032
0
SLANG_RAW("[__readNone]\n")
11033
0
SLANG_RAW("[require(cuda_glsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11034
0
SLANG_RAW("vector<float16_t, N> f32tof16_(vector<float, N> value)\n")
11035
0
SLANG_RAW("{\n")
11036
0
SLANG_RAW("    __target_switch\n")
11037
0
SLANG_RAW("    {\n")
11038
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__float2half\";\n")
11039
0
SLANG_RAW("    case metal: __intrinsic_asm \"$TR($0)\";\n")
11040
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11041
0
SLANG_RAW("        OpFConvert $$vector<float16_t, N> result $value\n")
11042
0
SLANG_RAW("    };\n")
11043
0
SLANG_RAW("    default:\n")
11044
0
SLANG_RAW("        VECTOR_MAP_UNARY(float16_t, N, f32tof16_, value);\n")
11045
0
SLANG_RAW("    }\n")
11046
0
SLANG_RAW("}\n")
11047
0
SLANG_RAW("\n")
11048
0
SLANG_RAW("// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
11049
0
SLANG_RAW("\n")
11050
0
SLANG_RAW("/// Flip vector to face forward, if needed.\n")
11051
0
SLANG_RAW("/// @param n The vector to orient.\n")
11052
0
SLANG_RAW("/// @param i The incident vector.\n")
11053
0
SLANG_RAW("/// @param ng The geometric normal vector.\n")
11054
0
SLANG_RAW("/// @return `n` if the dot product of `ng` and `i` is less than 0, otherwise `-n`.\n")
11055
0
SLANG_RAW("/// @category math\n")
11056
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11057
0
SLANG_RAW("[__readNone]\n")
11058
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11059
0
SLANG_RAW("vector<T,N> faceforward(vector<T,N> n, vector<T,N> i, vector<T,N> ng)\n")
11060
0
SLANG_RAW("{\n")
11061
0
SLANG_RAW("    __target_switch\n")
11062
0
SLANG_RAW("    {\n")
11063
0
SLANG_RAW("    case glsl: __intrinsic_asm \"faceforward\";\n")
11064
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"faceforward\";\n")
11065
0
SLANG_RAW("    case metal: __intrinsic_asm \"faceforward\";\n")
11066
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11067
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 FaceForward $n $i $ng\n")
11068
0
SLANG_RAW("    };\n")
11069
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"faceForward\";\n")
11070
0
SLANG_RAW("    default:\n")
11071
0
SLANG_RAW("        return dot(ng, i) < T(0.0f) ? n : -n;\n")
11072
0
SLANG_RAW("    }\n")
11073
0
SLANG_RAW("}\n")
11074
0
SLANG_RAW("\n")
11075
0
SLANG_RAW("// Helper functions for Metal target\n")
11076
0
SLANG_RAW("internal int __metal_clz(int value)\n")
11077
0
SLANG_RAW("{\n")
11078
0
SLANG_RAW("    __target_switch\n")
11079
0
SLANG_RAW("    {\n")
11080
0
SLANG_RAW("    case metal: __intrinsic_asm \"clz\";\n")
11081
0
SLANG_RAW("    }\n")
11082
0
SLANG_RAW("}\n")
11083
0
SLANG_RAW("\n")
11084
0
SLANG_RAW("internal uint __metal_clz(uint value)\n")
11085
0
SLANG_RAW("{\n")
11086
0
SLANG_RAW("    __target_switch\n")
11087
0
SLANG_RAW("    {\n")
11088
0
SLANG_RAW("    case metal: __intrinsic_asm \"clz\";\n")
11089
0
SLANG_RAW("    }\n")
11090
0
SLANG_RAW("}\n")
11091
0
SLANG_RAW("\n")
11092
0
SLANG_RAW("internal int __metal_ctz(int value)\n")
11093
0
SLANG_RAW("{\n")
11094
0
SLANG_RAW("    __target_switch\n")
11095
0
SLANG_RAW("    {\n")
11096
0
SLANG_RAW("    case metal: __intrinsic_asm \"ctz\";\n")
11097
0
SLANG_RAW("    }\n")
11098
0
SLANG_RAW("}\n")
11099
0
SLANG_RAW("\n")
11100
0
SLANG_RAW("internal uint __metal_ctz(uint value)\n")
11101
0
SLANG_RAW("{\n")
11102
0
SLANG_RAW("    __target_switch\n")
11103
0
SLANG_RAW("    {\n")
11104
0
SLANG_RAW("    case metal: __intrinsic_asm \"ctz\";\n")
11105
0
SLANG_RAW("    }\n")
11106
0
SLANG_RAW("}\n")
11107
0
SLANG_RAW("\n")
11108
0
SLANG_RAW("/// Find first set bit starting at high bit and working down.\n")
11109
0
SLANG_RAW("/// @param value The value to find set bits in.\n")
11110
0
SLANG_RAW("/// @return The bit index number of the most significant bit,\n")
11111
0
SLANG_RAW("///         or returns -1 if `value` is either 0 if `value is\n")
11112
0
SLANG_RAW("///         a signed type and equal to -1.\n")
11113
0
SLANG_RAW("/// @remarks If `value` is unsigned, or signed with positive value, the bit index returned is the highest 1-bit.\n")
11114
0
SLANG_RAW("///          If `value` is signed with negative value, the bit index returned is the highest 0-bit.\n")
11115
0
SLANG_RAW("///          For SPIR-V, this function maps to GLSL extended instruction `FindSMsb` if `value` is signed,\n")
11116
0
SLANG_RAW("///          or `FindUMsb` if `value` is unsigned.\n")
11117
0
SLANG_RAW("/// @category bitops Bit operation functions\n")
11118
0
SLANG_RAW("[__readNone]\n")
11119
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11120
0
SLANG_RAW("int firstbithigh(int value)\n")
11121
0
SLANG_RAW("{\n")
11122
0
SLANG_RAW("    __target_switch\n")
11123
0
SLANG_RAW("    {\n")
11124
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_firstbithigh($0)\";\n")
11125
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_firstbithigh($0)\";\n")
11126
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findMSB\";\n")
11127
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbithigh\";\n")
11128
0
SLANG_RAW("    case metal:\n")
11129
0
SLANG_RAW("        {\n")
11130
0
SLANG_RAW("            if ((int)value < 0)\n")
11131
0
SLANG_RAW("                value = ~value;\n")
11132
0
SLANG_RAW("            if (value == 0)\n")
11133
0
SLANG_RAW("                return ~0u;\n")
11134
0
SLANG_RAW("            return 31 - __metal_clz(value);\n")
11135
0
SLANG_RAW("        }\n")
11136
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11137
0
SLANG_RAW("        OpExtInst $$int result glsl450 FindSMsb $value\n")
11138
0
SLANG_RAW("    };\n")
11139
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstLeadingBit\";\n")
11140
0
SLANG_RAW("    }\n")
11141
0
SLANG_RAW("}\n")
11142
0
SLANG_RAW("\n")
11143
0
SLANG_RAW("__generic<let N : int>\n")
11144
0
SLANG_RAW("[__readNone]\n")
11145
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11146
0
SLANG_RAW("vector<int, N> firstbithigh(vector<int, N> value)\n")
11147
0
SLANG_RAW("{\n")
11148
0
SLANG_RAW("    __target_switch\n")
11149
0
SLANG_RAW("    {\n")
11150
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findMSB\";\n")
11151
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbithigh\";\n")
11152
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11153
0
SLANG_RAW("        OpExtInst $$vector<int, N> result glsl450 FindSMsb $value\n")
11154
0
SLANG_RAW("    };\n")
11155
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstLeadingBit\";\n")
11156
0
SLANG_RAW("    default:\n")
11157
0
SLANG_RAW("        VECTOR_MAP_UNARY(int, N, firstbithigh, value);\n")
11158
0
SLANG_RAW("    }\n")
11159
0
SLANG_RAW("}\n")
11160
0
SLANG_RAW("\n")
11161
0
SLANG_RAW("[__readNone]\n")
11162
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11163
0
SLANG_RAW("uint firstbithigh(uint value)\n")
11164
0
SLANG_RAW("{\n")
11165
0
SLANG_RAW("    __target_switch\n")
11166
0
SLANG_RAW("    {\n")
11167
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_firstbithigh($0)\";\n")
11168
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_firstbithigh($0)\";\n")
11169
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findMSB\";\n")
11170
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbithigh\";\n")
11171
0
SLANG_RAW("    case metal:\n")
11172
0
SLANG_RAW("        {\n")
11173
0
SLANG_RAW("            if ((int)value < 0)\n")
11174
0
SLANG_RAW("                value = ~value;\n")
11175
0
SLANG_RAW("            if (value == 0)\n")
11176
0
SLANG_RAW("                return ~0u;\n")
11177
0
SLANG_RAW("            return 31 - __metal_clz(value);\n")
11178
0
SLANG_RAW("        }\n")
11179
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11180
0
SLANG_RAW("        OpExtInst $$uint result glsl450 FindUMsb $value\n")
11181
0
SLANG_RAW("    };\n")
11182
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstLeadingBit\";\n")
11183
0
SLANG_RAW("    }\n")
11184
0
SLANG_RAW("}\n")
11185
0
SLANG_RAW("\n")
11186
0
SLANG_RAW("__generic<let N : int>\n")
11187
0
SLANG_RAW("[__readNone]\n")
11188
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11189
0
SLANG_RAW("vector<uint,N> firstbithigh(vector<uint,N> value)\n")
11190
0
SLANG_RAW("{\n")
11191
0
SLANG_RAW("    __target_switch\n")
11192
0
SLANG_RAW("    {\n")
11193
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findMSB\";\n")
11194
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbithigh\";\n")
11195
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11196
0
SLANG_RAW("        OpExtInst $$vector<uint,N> result glsl450 FindUMsb $value\n")
11197
0
SLANG_RAW("    };\n")
11198
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstLeadingBit\";\n")
11199
0
SLANG_RAW("    default:\n")
11200
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, firstbithigh, value);\n")
11201
0
SLANG_RAW("    }\n")
11202
0
SLANG_RAW("}\n")
11203
0
SLANG_RAW("\n")
11204
0
SLANG_RAW("/// Find first set bit starting at low bit and working up.\n")
11205
0
SLANG_RAW("/// @param value The value to find set bits in.\n")
11206
0
SLANG_RAW("/// @return The bit index number of the least significant set bit,\n")
11207
0
SLANG_RAW("///         or all ones (-1 when interpretted as signed) if `value` is 0.\n")
11208
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to GLSL extended instruction `FindILsb`.\n")
11209
0
SLANG_RAW("/// @category bitops\n")
11210
0
SLANG_RAW("[__readNone]\n")
11211
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11212
0
SLANG_RAW("int firstbitlow(int value)\n")
11213
0
SLANG_RAW("{\n")
11214
0
SLANG_RAW("    __target_switch\n")
11215
0
SLANG_RAW("    {\n")
11216
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_firstbitlow($0)\";\n")
11217
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_firstbitlow($0)\";\n")
11218
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findLSB\";\n")
11219
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbitlow\";\n")
11220
0
SLANG_RAW("    case metal: return (value==0) ? -1 : __metal_ctz(value);\n")
11221
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11222
0
SLANG_RAW("        OpExtInst $$int result glsl450 FindILsb $value\n")
11223
0
SLANG_RAW("    };\n")
11224
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstTrailingBit\";\n")
11225
0
SLANG_RAW("    }\n")
11226
0
SLANG_RAW("}\n")
11227
0
SLANG_RAW("\n")
11228
0
SLANG_RAW("__generic<let N : int>\n")
11229
0
SLANG_RAW("[__readNone]\n")
11230
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11231
0
SLANG_RAW("vector<int,N> firstbitlow(vector<int,N> value)\n")
11232
0
SLANG_RAW("{\n")
11233
0
SLANG_RAW("    __target_switch\n")
11234
0
SLANG_RAW("    {\n")
11235
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findLSB\";\n")
11236
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbitlow\";\n")
11237
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11238
0
SLANG_RAW("        OpExtInst $$vector<int,N> result glsl450 FindILsb $value\n")
11239
0
SLANG_RAW("    };\n")
11240
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstTrailingBit\";\n")
11241
0
SLANG_RAW("    default:\n")
11242
0
SLANG_RAW("        VECTOR_MAP_UNARY(int, N, firstbitlow, value);\n")
11243
0
SLANG_RAW("    }\n")
11244
0
SLANG_RAW("}\n")
11245
0
SLANG_RAW("\n")
11246
0
SLANG_RAW("[__readNone]\n")
11247
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11248
0
SLANG_RAW("uint firstbitlow(uint value)\n")
11249
0
SLANG_RAW("{\n")
11250
0
SLANG_RAW("    __target_switch\n")
11251
0
SLANG_RAW("    {\n")
11252
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_firstbitlow($0)\";\n")
11253
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_firstbitlow($0)\";\n")
11254
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findLSB\";\n")
11255
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbitlow\";\n")
11256
0
SLANG_RAW("    case metal: return (value==0) ? -1 : __metal_ctz(value);\n")
11257
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11258
0
SLANG_RAW("        OpExtInst $$uint result glsl450 FindILsb $value\n")
11259
0
SLANG_RAW("    };\n")
11260
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstTrailingBit\";\n")
11261
0
SLANG_RAW("    }\n")
11262
0
SLANG_RAW("}\n")
11263
0
SLANG_RAW("\n")
11264
0
SLANG_RAW("__generic<let N : int>\n")
11265
0
SLANG_RAW("[__readNone]\n")
11266
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11267
0
SLANG_RAW("vector<uint,N> firstbitlow(vector<uint,N> value)\n")
11268
0
SLANG_RAW("{\n")
11269
0
SLANG_RAW("    __target_switch\n")
11270
0
SLANG_RAW("    {\n")
11271
0
SLANG_RAW("    case glsl: __intrinsic_asm \"findLSB\";\n")
11272
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"firstbitlow\";\n")
11273
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11274
0
SLANG_RAW("        OpExtInst $$vector<uint,N> result glsl450 FindILsb $value\n")
11275
0
SLANG_RAW("    };\n")
11276
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"firstTrailingBit\";\n")
11277
0
SLANG_RAW("    default:\n")
11278
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, firstbitlow, value);\n")
11279
0
SLANG_RAW("    }\n")
11280
0
SLANG_RAW("}\n")
11281
0
SLANG_RAW("\n")
11282
0
SLANG_RAW("/// Floor. Returns the largest integer value not greater than `x`.\n")
11283
0
SLANG_RAW("/// @param x The input value.\n")
11284
0
SLANG_RAW("/// @return The largest integer value not greater than `x`.\n")
11285
0
SLANG_RAW("/// @category math\n")
11286
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11287
0
SLANG_RAW("[__readNone]\n")
11288
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11289
0
SLANG_RAW("T floor(T x)\n")
11290
0
SLANG_RAW("{\n")
11291
0
SLANG_RAW("    __target_switch\n")
11292
0
SLANG_RAW("    {\n")
11293
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_floor($0)\";\n")
11294
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_floor($0)\";\n")
11295
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floor\";\n")
11296
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"floor\";\n")
11297
0
SLANG_RAW("    case metal: __intrinsic_asm \"floor\";\n")
11298
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11299
0
SLANG_RAW("        OpExtInst $$T result glsl450 Floor $x\n")
11300
0
SLANG_RAW("    };\n")
11301
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"floor\";\n")
11302
0
SLANG_RAW("    }\n")
11303
0
SLANG_RAW("}\n")
11304
0
SLANG_RAW("\n")
11305
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11306
0
SLANG_RAW("[__readNone]\n")
11307
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11308
0
SLANG_RAW("vector<T, N> floor(vector<T, N> x)\n")
11309
0
SLANG_RAW("{\n")
11310
0
SLANG_RAW("    __target_switch\n")
11311
0
SLANG_RAW("    {\n")
11312
0
SLANG_RAW("    case glsl: __intrinsic_asm \"floor\";\n")
11313
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"floor\";\n")
11314
0
SLANG_RAW("    case metal: __intrinsic_asm \"floor\";\n")
11315
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11316
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Floor $x\n")
11317
0
SLANG_RAW("    };\n")
11318
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"floor\";\n")
11319
0
SLANG_RAW("    default:\n")
11320
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, floor, x);\n")
11321
0
SLANG_RAW("    }\n")
11322
0
SLANG_RAW("}\n")
11323
0
SLANG_RAW("\n")
11324
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11325
0
SLANG_RAW("[__readNone]\n")
11326
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11327
0
SLANG_RAW("matrix<T, N, M> floor(matrix<T, N, M> x)\n")
11328
0
SLANG_RAW("{\n")
11329
0
SLANG_RAW("    __target_switch\n")
11330
0
SLANG_RAW("    {\n")
11331
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"floor\";\n")
11332
0
SLANG_RAW("    default:\n")
11333
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, floor, x);\n")
11334
0
SLANG_RAW("    }\n")
11335
0
SLANG_RAW("}\n")
11336
0
SLANG_RAW("\n")
11337
0
SLANG_RAW("/// Fused multiply-add.\n")
11338
0
SLANG_RAW("/// @param a The first value to multiply.\n")
11339
0
SLANG_RAW("/// @param b The second value to multiply.\n")
11340
0
SLANG_RAW("/// @param c The value to add to the product of `a` and `b`.\n")
11341
0
SLANG_RAW("/// @return The result of `a * b + c`.\n")
11342
0
SLANG_RAW("/// @category math\n")
11343
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11344
0
SLANG_RAW("[__readNone]\n")
11345
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11346
0
SLANG_RAW("T fma(T a, T b, T c)\n")
11347
0
SLANG_RAW("{\n")
11348
0
SLANG_RAW("    __target_switch\n")
11349
0
SLANG_RAW("    {\n")
11350
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
11351
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
11352
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
11353
0
SLANG_RAW("    case hlsl:\n")
11354
0
SLANG_RAW("        if (__isFloat<T>() || __isHalf<T>())\n")
11355
0
SLANG_RAW("            return mad(a, b, c);\n")
11356
0
SLANG_RAW("        else\n")
11357
0
SLANG_RAW("            __intrinsic_asm \"fma($0, $1, $2)\";\n")
11358
0
SLANG_RAW("    case metal: __intrinsic_asm \"fma\";\n")
11359
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11360
0
SLANG_RAW("        OpExtInst $$T result glsl450 Fma $a $b $c\n")
11361
0
SLANG_RAW("    };\n")
11362
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fma\";\n")
11363
0
SLANG_RAW("    default:\n")
11364
0
SLANG_RAW("        return a*b + c;\n")
11365
0
SLANG_RAW("    }\n")
11366
0
SLANG_RAW("}\n")
11367
0
SLANG_RAW("\n")
11368
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11369
0
SLANG_RAW("[__readNone]\n")
11370
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11371
0
SLANG_RAW("vector<T, N> fma(vector<T, N> a, vector<T, N> b, vector<T, N> c)\n")
11372
0
SLANG_RAW("{\n")
11373
0
SLANG_RAW("    __target_switch\n")
11374
0
SLANG_RAW("    {\n")
11375
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
11376
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"fma\";\n")
11377
0
SLANG_RAW("    case metal: __intrinsic_asm \"fma\";\n")
11378
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11379
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Fma $a $b $c\n")
11380
0
SLANG_RAW("    };\n")
11381
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fma\";\n")
11382
0
SLANG_RAW("    default:\n")
11383
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, fma, a, b, c);\n")
11384
0
SLANG_RAW("    }\n")
11385
0
SLANG_RAW("}\n")
11386
0
SLANG_RAW("\n")
11387
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11388
0
SLANG_RAW("[__readNone]\n")
11389
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
11390
0
SLANG_RAW("matrix<T, N, M> fma(matrix<T, N, M> a, matrix<T, N, M> b, matrix<T, N, M> c)\n")
11391
0
SLANG_RAW("{\n")
11392
0
SLANG_RAW("    __target_switch\n")
11393
0
SLANG_RAW("    {\n")
11394
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"fma\";\n")
11395
0
SLANG_RAW("    default:\n")
11396
0
SLANG_RAW("        MATRIX_MAP_TRINARY(T, N, M, fma, a, b, c);\n")
11397
0
SLANG_RAW("    }\n")
11398
0
SLANG_RAW("}\n")
11399
0
SLANG_RAW("\n")
11400
0
SLANG_RAW("/// Floating point remainder of x/y.\n")
11401
0
SLANG_RAW("/// The floating-point remainder is calculated such that x = i * y + f,\n")
11402
0
SLANG_RAW("/// where i is an integer, f has the same sign as x, and the absolute value\n")
11403
0
SLANG_RAW("/// of f is less than the absolute value of y.\n")
11404
0
SLANG_RAW("/// @param x The dividend.\n")
11405
0
SLANG_RAW("/// @param y The divisor.\n")
11406
0
SLANG_RAW("/// @return The floating-point remainder of x/y.\n")
11407
0
SLANG_RAW("/// @category math\n")
11408
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11409
0
SLANG_RAW("[__readNone]\n")
11410
0
SLANG_RAW("[ForceInline]\n")
11411
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11412
0
SLANG_RAW("T fmod(T x, T y)\n")
11413
0
SLANG_RAW("{\n")
11414
0
SLANG_RAW("    // In HLSL, `fmod` returns a remainder.\n")
11415
0
SLANG_RAW("    // Definition of `fmod` in HLSL is,\n")
11416
0
SLANG_RAW("    // \"The floating-point remainder is calculated such that x = i * y + f,\n")
11417
0
SLANG_RAW("    // where i is an integer, f has the same sign as x, and the absolute value\n")
11418
0
SLANG_RAW("    // of f is less than the absolute value of y.\"\n")
11419
0
SLANG_RAW("    //\n")
11420
0
SLANG_RAW("    // In GLSL, `mod` is a Modulus function.\n")
11421
0
SLANG_RAW("    // OpenGL document defines \"Modulus\" as \"Returns x - y * floor(x / y)\".\n")
11422
0
SLANG_RAW("    // The use of \"Floor()\" makes the difference.\n")
11423
0
SLANG_RAW("    //\n")
11424
0
SLANG_RAW("    // In Metal, `fmod` is Modulus function.\n")
11425
0
SLANG_RAW("    // Metal document defines it as \"Returns x - y * trunc(x/y)\".\n")
11426
0
SLANG_RAW("    // Note that the function name is same to HLSL but it behaves differently.\n")
11427
0
SLANG_RAW("    //\n")
11428
0
SLANG_RAW("    // The tricky ones are when x or y is a negative value.\n")
11429
0
SLANG_RAW("    //\n")
11430
0
SLANG_RAW("    //       | Remainder | Modulus\n")
11431
0
SLANG_RAW("    //  x  y | x= i*y +f | x-y*floor(x/y)\n")
11432
0
SLANG_RAW("    // ------+-----------+------------------------------\n")
11433
0
SLANG_RAW("    //  4  3 | 4= 1*3 +1 | 4-3*floor( 4/3) = 4-3* 1 = 1\n")
11434
0
SLANG_RAW("    //  3  3 | 3= 1*3 +0 | 3-3*floor( 3/3) = 3-3* 1 = 0\n")
11435
0
SLANG_RAW("    //  2  3 | 2= 0*3 +2 | 2-3*floor( 2/3) = 2-3* 0 = 2\n")
11436
0
SLANG_RAW("    //  1  3 | 1= 0*3 +1 | 1-3*floor( 1/3) = 1-3* 0 = 1\n")
11437
0
SLANG_RAW("    //  0  3 | 0= 0*3 +0 | 0-3*floor( 0/3) = 0-3* 0 = 0\n")
11438
0
SLANG_RAW("    // -1  3 |-1= 0*3 -1 |-1-3*floor(-1/3) =-1-3*-1 = 2\n")
11439
0
SLANG_RAW("    // -2  3 |-2= 0*3 -2 |-2-3*floor(-2/3) =-2-3*-1 = 1\n")
11440
0
SLANG_RAW("    // -3  3 |-3=-1*3  0 |-3-3*floor(-3/3) =-3-3*-1 = 0\n")
11441
0
SLANG_RAW("    // -4  3 |-4=-1*3 -1 |-4-3*floor(-4/3) =-4-3*-2 = 2\n")
11442
0
SLANG_RAW("    //\n")
11443
0
SLANG_RAW("    // When y is a negative value,\n")
11444
0
SLANG_RAW("    //\n")
11445
0
SLANG_RAW("    //       | Remainder | Modulus\n")
11446
0
SLANG_RAW("    //  x  y | x= i*y +f | x-y*floor(x/y)\n")
11447
0
SLANG_RAW("    // ------+-----------+------------------------------\n")
11448
0
SLANG_RAW("    //  4 -3 | 4=-1*-3+1 | 4+3*floor( 4/-3) = 4+3*-2 =-2\n")
11449
0
SLANG_RAW("    //  3 -3 | 3=-1*-3+0 | 3+3*floor( 3/-3) = 3+3*-1 = 0\n")
11450
0
SLANG_RAW("    //  2 -3 | 2= 0*-3+2 | 2+3*floor( 2/-3) = 2+3*-1 =-1\n")
11451
0
SLANG_RAW("    //  1 -3 | 1= 0*-3+1 | 1+3*floor( 1/-3) = 1+3*-1 =-2\n")
11452
0
SLANG_RAW("    //  0 -3 | 0= 0*-3+0 | 0+3*floor( 0/-3) = 0+3* 0 = 0\n")
11453
0
SLANG_RAW("    // -1 -3 |-1= 0*-3-1 |-1+3*floor(-1/-3) =-1+3* 0 =-1\n")
11454
0
SLANG_RAW("    // -2 -3 |-2= 0*-3-2 |-2+3*floor(-2/-3) =-2+3* 0 =-2\n")
11455
0
SLANG_RAW("    // -3 -3 |-3= 1*-3 0 |-3+3*floor(-3/-3) =-3+3* 1 = 0\n")
11456
0
SLANG_RAW("    // -4 -3 |-4= 1*-3-1 |-4+3*floor(-4/-3) =-4+3* 1 =-1\n")
11457
0
SLANG_RAW("\n")
11458
0
SLANG_RAW("    __target_switch\n")
11459
0
SLANG_RAW("    {\n")
11460
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_fmod($0, $1)\";\n")
11461
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_fmod($0, $1)\";\n")
11462
0
SLANG_RAW("    case glsl:\n")
11463
0
SLANG_RAW("        // GLSL doesn't have a function for remainder.\n")
11464
0
SLANG_RAW("        __intrinsic_asm \"(($0 < 0.0) ? -mod(-$0,abs($1)) : mod($0,abs($1)))\";\n")
11465
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"fmod\";\n")
11466
0
SLANG_RAW("    case metal:\n")
11467
0
SLANG_RAW("        // Metal doesn't have a function for remainder.\n")
11468
0
SLANG_RAW("        __intrinsic_asm \"(($0 < 0.0) ? -fmod(-$0,abs($1)) : fmod($0,abs($1)))\";\n")
11469
0
SLANG_RAW("    case spirv:\n")
11470
0
SLANG_RAW("        // OpFRem return \"The floating-point remainder whose sign\n")
11471
0
SLANG_RAW("        // matches the sign of Operand 1\", where Operand 1 is \"x\".\n")
11472
0
SLANG_RAW("        return spirv_asm\n")
11473
0
SLANG_RAW("        {\n")
11474
0
SLANG_RAW("            result:$$T = OpFRem $x $y\n")
11475
0
SLANG_RAW("        };\n")
11476
0
SLANG_RAW("    case wgsl:\n")
11477
0
SLANG_RAW("        __intrinsic_asm \"(($0) % ($1))\";\n")
11478
0
SLANG_RAW("    }\n")
11479
0
SLANG_RAW("}\n")
11480
0
SLANG_RAW("\n")
11481
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11482
0
SLANG_RAW("[__readNone]\n")
11483
0
SLANG_RAW("[ForceInline]\n")
11484
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11485
0
SLANG_RAW("vector<T, N> fmod(vector<T, N> x, vector<T, N> y)\n")
11486
0
SLANG_RAW("{\n")
11487
0
SLANG_RAW("    __target_switch\n")
11488
0
SLANG_RAW("    {\n")
11489
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"fmod\";\n")
11490
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11491
0
SLANG_RAW("        result:$$vector<T,N> = OpFRem $x $y\n")
11492
0
SLANG_RAW("    };\n")
11493
0
SLANG_RAW("    default:\n")
11494
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, fmod, x, y);\n")
11495
0
SLANG_RAW("    }\n")
11496
0
SLANG_RAW("}\n")
11497
0
SLANG_RAW("\n")
11498
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11499
0
SLANG_RAW("[__readNone]\n")
11500
0
SLANG_RAW("[ForceInline]\n")
11501
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11502
0
SLANG_RAW("matrix<T, N, M> fmod(matrix<T, N, M> x, matrix<T, N, M> y)\n")
11503
0
SLANG_RAW("{\n")
11504
0
SLANG_RAW("    __target_switch\n")
11505
0
SLANG_RAW("    {\n")
11506
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"fmod\";\n")
11507
0
SLANG_RAW("    default:\n")
11508
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, fmod, x, y);\n")
11509
0
SLANG_RAW("    }\n")
11510
0
SLANG_RAW("}\n")
11511
0
SLANG_RAW("\n")
11512
0
SLANG_RAW("/// Extract the fractional part of a floating-point number.\n")
11513
0
SLANG_RAW("/// @param x The input value.\n")
11514
0
SLANG_RAW("/// @return The fractional part of `x`.\n")
11515
0
SLANG_RAW("/// @category math\n")
11516
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11517
0
SLANG_RAW("[__readNone]\n")
11518
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11519
0
SLANG_RAW("T frac(T x)\n")
11520
0
SLANG_RAW("{\n")
11521
0
SLANG_RAW("    __target_switch\n")
11522
0
SLANG_RAW("    {\n")
11523
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_frac($0)\";\n")
11524
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_frac($0)\";\n")
11525
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fract\";\n")
11526
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"frac\";\n")
11527
0
SLANG_RAW("    case metal: __intrinsic_asm \"fract\";\n")
11528
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11529
0
SLANG_RAW("        OpExtInst $$T result glsl450 Fract $x\n")
11530
0
SLANG_RAW("    };\n")
11531
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fract\";\n")
11532
0
SLANG_RAW("    }\n")
11533
0
SLANG_RAW("}\n")
11534
0
SLANG_RAW("\n")
11535
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11536
0
SLANG_RAW("[__readNone]\n")
11537
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11538
0
SLANG_RAW("vector<T, N> frac(vector<T, N> x)\n")
11539
0
SLANG_RAW("{\n")
11540
0
SLANG_RAW("    __target_switch\n")
11541
0
SLANG_RAW("    {\n")
11542
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fract\";\n")
11543
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"frac\";\n")
11544
0
SLANG_RAW("    case metal: __intrinsic_asm \"fract\";\n")
11545
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11546
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Fract $x\n")
11547
0
SLANG_RAW("    };\n")
11548
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fract\";\n")
11549
0
SLANG_RAW("    default:\n")
11550
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, frac, x);\n")
11551
0
SLANG_RAW("    }\n")
11552
0
SLANG_RAW("}\n")
11553
0
SLANG_RAW("\n")
11554
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11555
0
SLANG_RAW("[__readNone]\n")
11556
0
SLANG_RAW("matrix<T, N, M> frac(matrix<T, N, M> x)\n")
11557
0
SLANG_RAW("{\n")
11558
0
SLANG_RAW("    MATRIX_MAP_UNARY(T, N, M, frac, x);\n")
11559
0
SLANG_RAW("}\n")
11560
0
SLANG_RAW("\n")
11561
0
SLANG_RAW("/// Extract the fractional part of a floating-point number.\n")
11562
0
SLANG_RAW("/// @param x The input value.\n")
11563
0
SLANG_RAW("/// @return The fractional part of `x`.\n")
11564
0
SLANG_RAW("/// @category math\n")
11565
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11566
0
SLANG_RAW("[__readNone]\n")
11567
0
SLANG_RAW("[ForceInline]\n")
11568
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11569
0
SLANG_RAW("T fract(T x)\n")
11570
0
SLANG_RAW("{\n")
11571
0
SLANG_RAW("    return frac(x);\n")
11572
0
SLANG_RAW("}\n")
11573
0
SLANG_RAW("\n")
11574
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N:int>\n")
11575
0
SLANG_RAW("[__readNone]\n")
11576
0
SLANG_RAW("[ForceInline]\n")
11577
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11578
0
SLANG_RAW("vector<T, N> fract(vector<T, N> x)\n")
11579
0
SLANG_RAW("{\n")
11580
0
SLANG_RAW("    return frac(x);\n")
11581
0
SLANG_RAW("}\n")
11582
0
SLANG_RAW("\n")
11583
0
SLANG_RAW("/// Split float into mantissa and exponent.\n")
11584
0
SLANG_RAW("/// @param x The input value.\n")
11585
0
SLANG_RAW("/// @param[out] exp The output exponent.\n")
11586
0
SLANG_RAW("/// @return The mantissa of `x`.\n")
11587
0
SLANG_RAW("/// @category math\n")
11588
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11589
0
SLANG_RAW("[__readNone]\n")
11590
0
SLANG_RAW("[ForceInline]\n")
11591
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11592
0
SLANG_RAW("T frexp(T x, out int exp)\n")
11593
0
SLANG_RAW("{\n")
11594
0
SLANG_RAW("    __target_switch\n")
11595
0
SLANG_RAW("    {\n")
11596
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_frexp($0, $1)\";\n")
11597
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_frexp($0, $1)\";\n")
11598
0
SLANG_RAW("    case glsl: __intrinsic_asm \"frexp\";\n")
11599
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"frexp\";\n")
11600
0
SLANG_RAW("    case metal: __intrinsic_asm \"frexp($0, *($1))\";\n")
11601
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11602
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 Frexp $x &exp\n")
11603
0
SLANG_RAW("    };\n")
11604
0
SLANG_RAW("    case wgsl:\n")
11605
0
SLANG_RAW("        T fract;\n")
11606
0
SLANG_RAW("        __wgsl_frexp<T>(x, fract, exp);\n")
11607
0
SLANG_RAW("        return fract;\n")
11608
0
SLANG_RAW("    }\n")
11609
0
SLANG_RAW("}\n")
11610
0
SLANG_RAW("\n")
11611
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11612
0
SLANG_RAW("[__readNone]\n")
11613
0
SLANG_RAW("[ForceInline]\n")
11614
0
SLANG_RAW("[require(wgsl)]\n")
11615
0
SLANG_RAW("void __wgsl_frexp(T x, out T fract, out int exp)\n")
11616
0
SLANG_RAW("{\n")
11617
0
SLANG_RAW("    __intrinsic_asm \"{ var s = frexp($0); ($1) = s.fract; ($2) = s.exp; }\";\n")
11618
0
SLANG_RAW("}\n")
11619
0
SLANG_RAW("\n")
11620
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11621
0
SLANG_RAW("[__readNone]\n")
11622
0
SLANG_RAW("[ForceInline]\n")
11623
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11624
0
SLANG_RAW("vector<T, N> frexp(vector<T, N> x, out vector<int, N> exp)\n")
11625
0
SLANG_RAW("{\n")
11626
0
SLANG_RAW("    __target_switch\n")
11627
0
SLANG_RAW("    {\n")
11628
0
SLANG_RAW("    case glsl: __intrinsic_asm \"frexp\";\n")
11629
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"frexp\";\n")
11630
0
SLANG_RAW("    case metal: __intrinsic_asm \"frexp($0, *($1))\";\n")
11631
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
11632
0
SLANG_RAW("        result:$$vector<T, N> = OpExtInst glsl450 Frexp $x &exp\n")
11633
0
SLANG_RAW("    };\n")
11634
0
SLANG_RAW("    case wgsl:\n")
11635
0
SLANG_RAW("        vector<T,N> fract;\n")
11636
0
SLANG_RAW("        __wgsl_frexp<T>(x, fract, exp);\n")
11637
0
SLANG_RAW("        return fract;\n")
11638
0
SLANG_RAW("    default:\n")
11639
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, frexp, x, exp);\n")
11640
0
SLANG_RAW("    }\n")
11641
0
SLANG_RAW("}\n")
11642
0
SLANG_RAW("\n")
11643
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11644
0
SLANG_RAW("[__readNone]\n")
11645
0
SLANG_RAW("[ForceInline]\n")
11646
0
SLANG_RAW("[require(wgsl)]\n")
11647
0
SLANG_RAW("void __wgsl_frexp(vector<T, N> x, out vector<T, N> fract, out vector<int, N> exp)\n")
11648
0
SLANG_RAW("{\n")
11649
0
SLANG_RAW("    __intrinsic_asm \"{ var s = frexp($0); ($1) = s.fract; ($2) = s.exp; }\";\n")
11650
0
SLANG_RAW("}\n")
11651
0
SLANG_RAW("\n")
11652
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L : int>\n")
11653
0
SLANG_RAW("[__readNone]\n")
11654
0
SLANG_RAW("[ForceInline]\n")
11655
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
11656
0
SLANG_RAW("matrix<T, N, M> frexp(matrix<T, N, M> x, out matrix<int, N, M, L> exp)\n")
11657
0
SLANG_RAW("{\n")
11658
0
SLANG_RAW("    __target_switch\n")
11659
0
SLANG_RAW("    {\n")
11660
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"frexp\";\n")
11661
0
SLANG_RAW("    default:\n")
11662
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, frexp, x, exp);\n")
11663
0
SLANG_RAW("    }\n")
11664
0
SLANG_RAW("}\n")
11665
0
SLANG_RAW("\n")
11666
0
SLANG_RAW("/// Texture filter width.\n")
11667
0
SLANG_RAW("/// Calculates the sum abs(ddx(`p`)) + abs(ddy(`p`)).\n")
11668
0
SLANG_RAW("/// @param p The value to sum x and y partial derivative magnitudes for.\n")
11669
0
SLANG_RAW("/// @return The sum of abs(ddx(`p`)) and abs(ddy(`p`)).\n")
11670
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpFwidth`.\n")
11671
0
SLANG_RAW("/// @category derivative\n")
11672
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11673
0
SLANG_RAW("[__readNone]\n")
11674
0
SLANG_RAW("[require(glsl_hlsl_metal_spirv_wgsl, fragmentprocessing)]\n")
11675
0
SLANG_RAW("T fwidth(T p)\n")
11676
0
SLANG_RAW("{\n")
11677
0
SLANG_RAW("    __requireComputeDerivative();\n")
11678
0
SLANG_RAW("    __target_switch\n")
11679
0
SLANG_RAW("    {\n")
11680
0
SLANG_RAW("    case hlsl:\n")
11681
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11682
0
SLANG_RAW("    case glsl:\n")
11683
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11684
0
SLANG_RAW("    case metal:\n")
11685
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11686
0
SLANG_RAW("    case spirv:\n")
11687
0
SLANG_RAW("        return spirv_asm\n")
11688
0
SLANG_RAW("        {\n")
11689
0
SLANG_RAW("            OpFwidth $$T result $p;\n")
11690
0
SLANG_RAW("        };\n")
11691
0
SLANG_RAW("    case wgsl:\n")
11692
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11693
0
SLANG_RAW("    }\n")
11694
0
SLANG_RAW("}\n")
11695
0
SLANG_RAW("\n")
11696
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11697
0
SLANG_RAW("[__readNone]\n")
11698
0
SLANG_RAW("[require(glsl_hlsl_spirv_wgsl, fragmentprocessing)]\n")
11699
0
SLANG_RAW("vector<T, N> fwidth(vector<T, N> x)\n")
11700
0
SLANG_RAW("{\n")
11701
0
SLANG_RAW("    __requireComputeDerivative();\n")
11702
0
SLANG_RAW("    __target_switch\n")
11703
0
SLANG_RAW("    {\n")
11704
0
SLANG_RAW("    case hlsl:\n")
11705
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11706
0
SLANG_RAW("    case glsl:\n")
11707
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11708
0
SLANG_RAW("    case spirv:\n")
11709
0
SLANG_RAW("        return spirv_asm\n")
11710
0
SLANG_RAW("        {\n")
11711
0
SLANG_RAW("            OpFwidth $$vector<T, N> result $x;\n")
11712
0
SLANG_RAW("        };\n")
11713
0
SLANG_RAW("    case wgsl:\n")
11714
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11715
0
SLANG_RAW("    }\n")
11716
0
SLANG_RAW("}\n")
11717
0
SLANG_RAW("\n")
11718
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11719
0
SLANG_RAW("[__readNone]\n")
11720
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing)]\n")
11721
0
SLANG_RAW("matrix<T, N, M> fwidth(matrix<T, N, M> x)\n")
11722
0
SLANG_RAW("{\n")
11723
0
SLANG_RAW("    __target_switch\n")
11724
0
SLANG_RAW("    {\n")
11725
0
SLANG_RAW("    case hlsl:\n")
11726
0
SLANG_RAW("        __intrinsic_asm \"fwidth($0)\";\n")
11727
0
SLANG_RAW("    default:\n")
11728
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, fwidth, x);\n")
11729
0
SLANG_RAW("    }\n")
11730
0
SLANG_RAW("}\n")
11731
0
SLANG_RAW("\n")
11732
0
SLANG_RAW("/// Texture filter width (coarse).\n")
11733
0
SLANG_RAW("/// Calculates the sum abs(ddx_coarse(`p`)) + abs(ddy_coarse(`p`)).\n")
11734
0
SLANG_RAW("/// @param p The value to sum x and y partial derivative magnitudes for.\n")
11735
0
SLANG_RAW("/// @return The sum of abs(ddx_coarse(`p`)) and abs(ddy_coarse(`p`)).\n")
11736
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpFwidthCoarse`.\n")
11737
0
SLANG_RAW("/// @category derivative\n")
11738
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11739
0
SLANG_RAW("[__readNone]\n")
11740
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11741
0
SLANG_RAW("T fwidth_coarse(T p)\n")
11742
0
SLANG_RAW("{\n")
11743
0
SLANG_RAW("    __requireComputeDerivative();\n")
11744
0
SLANG_RAW("    __target_switch\n")
11745
0
SLANG_RAW("    {\n")
11746
0
SLANG_RAW("    case hlsl:\n")
11747
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_coarse($0)) + abs(ddy_coarse($0))\";\n")
11748
0
SLANG_RAW("    case glsl:\n")
11749
0
SLANG_RAW("        __intrinsic_asm \"fwidthCoarse($0)\";\n")
11750
0
SLANG_RAW("    case spirv:\n")
11751
0
SLANG_RAW("        return spirv_asm\n")
11752
0
SLANG_RAW("        {\n")
11753
0
SLANG_RAW("            OpCapability DerivativeControl;\n")
11754
0
SLANG_RAW("            OpFwidthCoarse $$T result $p;\n")
11755
0
SLANG_RAW("        };\n")
11756
0
SLANG_RAW("    }\n")
11757
0
SLANG_RAW("}\n")
11758
0
SLANG_RAW("\n")
11759
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11760
0
SLANG_RAW("[__readNone]\n")
11761
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11762
0
SLANG_RAW("vector<T, N> fwidth_coarse(vector<T, N> x)\n")
11763
0
SLANG_RAW("{\n")
11764
0
SLANG_RAW("    __requireComputeDerivative();\n")
11765
0
SLANG_RAW("    __target_switch\n")
11766
0
SLANG_RAW("    {\n")
11767
0
SLANG_RAW("    case hlsl:\n")
11768
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_coarse($0)) + abs(ddy_coarse($0))\";\n")
11769
0
SLANG_RAW("    case glsl:\n")
11770
0
SLANG_RAW("        __intrinsic_asm \"fwidthCoarse($0)\";\n")
11771
0
SLANG_RAW("    case spirv:\n")
11772
0
SLANG_RAW("        return spirv_asm\n")
11773
0
SLANG_RAW("        {\n")
11774
0
SLANG_RAW("            OpCapability DerivativeControl;\n")
11775
0
SLANG_RAW("            OpFwidthCoarse $$vector<T, N> result $x;\n")
11776
0
SLANG_RAW("        };\n")
11777
0
SLANG_RAW("    }\n")
11778
0
SLANG_RAW("}\n")
11779
0
SLANG_RAW("\n")
11780
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11781
0
SLANG_RAW("[__readNone]\n")
11782
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11783
0
SLANG_RAW("matrix<T, N, M> fwidth_coarse(matrix<T, N, M> x)\n")
11784
0
SLANG_RAW("{\n")
11785
0
SLANG_RAW("    __target_switch\n")
11786
0
SLANG_RAW("    {\n")
11787
0
SLANG_RAW("    case hlsl:\n")
11788
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_coarse($0)) + abs(ddy_coarse($0))\";\n")
11789
0
SLANG_RAW("    default:\n")
11790
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, fwidth_coarse, x);\n")
11791
0
SLANG_RAW("    }\n")
11792
0
SLANG_RAW("}\n")
11793
0
SLANG_RAW("\n")
11794
0
SLANG_RAW("/// Texture filter width (fine).\n")
11795
0
SLANG_RAW("/// Calculates the sum abs(ddx_fine(`p`)) + abs(ddy_fine(`p`)).\n")
11796
0
SLANG_RAW("/// @param p The value to sum x and y partial derivative magnitudes for.\n")
11797
0
SLANG_RAW("/// @return The sum of abs(ddx_fine(`p`)) and abs(ddy_fine(`p`)).\n")
11798
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpFwidthFine`.\n")
11799
0
SLANG_RAW("/// @category derivative\n")
11800
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
11801
0
SLANG_RAW("[__readNone]\n")
11802
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11803
0
SLANG_RAW("T fwidth_fine(T p)\n")
11804
0
SLANG_RAW("{\n")
11805
0
SLANG_RAW("    __requireComputeDerivative();\n")
11806
0
SLANG_RAW("    __target_switch\n")
11807
0
SLANG_RAW("    {\n")
11808
0
SLANG_RAW("    case hlsl:\n")
11809
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_fine($0)) + abs(ddy_fine($0))\";\n")
11810
0
SLANG_RAW("    case glsl:\n")
11811
0
SLANG_RAW("        __intrinsic_asm \"fwidthFine($0)\";\n")
11812
0
SLANG_RAW("    case spirv:\n")
11813
0
SLANG_RAW("        return spirv_asm\n")
11814
0
SLANG_RAW("        {\n")
11815
0
SLANG_RAW("            OpCapability DerivativeControl;\n")
11816
0
SLANG_RAW("            OpFwidthFine $$T result $p;\n")
11817
0
SLANG_RAW("        };\n")
11818
0
SLANG_RAW("    }\n")
11819
0
SLANG_RAW("}\n")
11820
0
SLANG_RAW("\n")
11821
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
11822
0
SLANG_RAW("[__readNone]\n")
11823
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11824
0
SLANG_RAW("vector<T, N> fwidth_fine(vector<T, N> x)\n")
11825
0
SLANG_RAW("{\n")
11826
0
SLANG_RAW("    __requireComputeDerivative();\n")
11827
0
SLANG_RAW("    __target_switch\n")
11828
0
SLANG_RAW("    {\n")
11829
0
SLANG_RAW("    case hlsl:\n")
11830
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_fine($0)) + abs(ddy_fine($0))\";\n")
11831
0
SLANG_RAW("    case glsl:\n")
11832
0
SLANG_RAW("        __intrinsic_asm \"fwidthFine($0)\";\n")
11833
0
SLANG_RAW("    case spirv:\n")
11834
0
SLANG_RAW("        return spirv_asm\n")
11835
0
SLANG_RAW("        {\n")
11836
0
SLANG_RAW("            OpCapability DerivativeControl;\n")
11837
0
SLANG_RAW("            OpFwidthFine $$vector<T, N> result $x;\n")
11838
0
SLANG_RAW("        };\n")
11839
0
SLANG_RAW("    }\n")
11840
0
SLANG_RAW("}\n")
11841
0
SLANG_RAW("\n")
11842
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
11843
0
SLANG_RAW("[__readNone]\n")
11844
0
SLANG_RAW("[require(glsl_hlsl_spirv, fragmentprocessing_derivativecontrol)]\n")
11845
0
SLANG_RAW("matrix<T, N, M> fwidth_fine(matrix<T, N, M> x)\n")
11846
0
SLANG_RAW("{\n")
11847
0
SLANG_RAW("    __target_switch\n")
11848
0
SLANG_RAW("    {\n")
11849
0
SLANG_RAW("    case hlsl:\n")
11850
0
SLANG_RAW("        __intrinsic_asm \"abs(ddx_fine($0)) + abs(ddy_fine($0))\";\n")
11851
0
SLANG_RAW("    default:\n")
11852
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, fwidth_fine, x);\n")
11853
0
SLANG_RAW("    }\n")
11854
0
SLANG_RAW("}\n")
11855
0
SLANG_RAW("\n")
11856
0
SLANG_RAW("__intrinsic_op(")
11857
0
SLANG_SPLICE(kIROp_ResolveVaryingInputRef
11858
0
)
11859
0
SLANG_RAW(")\n")
11860
0
SLANG_RAW("Ref<T, Access.Read, AddressSpace.VaryingInput> __ResolveVaryingInputRef<T>(__constref T attribute);\n")
11861
0
SLANG_RAW("\n")
11862
0
SLANG_RAW("__intrinsic_op(")
11863
0
SLANG_SPLICE(kIROp_GetPerVertexInputArray
11864
0
)
11865
0
SLANG_RAW(")\n")
11866
0
SLANG_RAW("Ref<Array<T, 3>, Access.Read, AddressSpace.VaryingInput> __GetPerVertexInputArray<T>(__constref T attribute);\n")
11867
0
SLANG_RAW("\n")
11868
0
SLANG_RAW("T __GetAttributeAtVertex<T>(__constref T attribute, uint vertexIndex)\n")
11869
0
SLANG_RAW("{\n")
11870
0
SLANG_RAW("    __intrinsic_asm \"GetAttributeAtVertex\";\n")
11871
0
SLANG_RAW("}\n")
11872
0
SLANG_RAW("\n")
11873
0
SLANG_RAW("/// Get the value of a vertex attribute at a specific vertex.\n")
11874
0
SLANG_RAW("///\n")
11875
0
SLANG_RAW("/// The `GetAttributeAtVertex()` function can be used in a fragment shader\n")
11876
0
SLANG_RAW("/// to get the value of the given `attribute` at the vertex of the primitive\n")
11877
0
SLANG_RAW("/// that corresponds to the given `vertexIndex`.\n")
11878
0
SLANG_RAW("///\n")
11879
0
SLANG_RAW("/// Note that the `attribute` must have been a declared varying input to\n")
11880
0
SLANG_RAW("/// the fragment shader with the `nointerpolation` modifier.\n")
11881
0
SLANG_RAW("///\n")
11882
0
SLANG_RAW("/// This function can be applied to scalars, vectors, and matrices of\n")
11883
0
SLANG_RAW("/// built-in scalar types.\n")
11884
0
SLANG_RAW("///\n")
11885
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
11886
0
SLANG_RAW("[__readNone]\n")
11887
0
SLANG_RAW("__glsl_version(450)\n")
11888
0
SLANG_RAW("__glsl_extension(GL_EXT_fragment_shader_barycentric)\n")
11889
0
SLANG_RAW("[require(glsl_hlsl_spirv, getattributeatvertex)]\n")
11890
0
SLANG_RAW("[KnownBuiltin(")
11891
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::GetAttributeAtVertex
11892
0
)
11893
0
SLANG_RAW(")]\n")
11894
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
11895
0
SLANG_RAW("T GetAttributeAtVertex(__constref T attribute, uint vertexIndex)\n")
11896
0
SLANG_RAW("{\n")
11897
0
SLANG_RAW("    __target_switch\n")
11898
0
SLANG_RAW("    {\n")
11899
0
SLANG_RAW("    case hlsl:\n")
11900
0
SLANG_RAW("        return __GetAttributeAtVertex(__ResolveVaryingInputRef(attribute), vertexIndex);\n")
11901
0
SLANG_RAW("    case glsl:\n")
11902
0
SLANG_RAW("    case spirv:\n")
11903
0
SLANG_RAW("        return __GetPerVertexInputArray(__ResolveVaryingInputRef(attribute))[vertexIndex];\n")
11904
0
SLANG_RAW("    }\n")
11905
0
SLANG_RAW("}\n")
11906
0
SLANG_RAW("\n")
11907
0
SLANG_RAW("/// Get the value of a vertex attribute at a specific vertex.\n")
11908
0
SLANG_RAW("///\n")
11909
0
SLANG_RAW("/// The `GetAttributeAtVertex()` function can be used in a fragment shader\n")
11910
0
SLANG_RAW("/// to get the value of the given `attribute` at the vertex of the primitive\n")
11911
0
SLANG_RAW("/// that corresponds to the given `vertexIndex`.\n")
11912
0
SLANG_RAW("///\n")
11913
0
SLANG_RAW("/// Note that the `attribute` must have been a declared varying input to\n")
11914
0
SLANG_RAW("/// the fragment shader with the `nointerpolation` modifier.\n")
11915
0
SLANG_RAW("///\n")
11916
0
SLANG_RAW("/// This function can be applied to scalars, vectors, and matrices of\n")
11917
0
SLANG_RAW("/// built-in scalar types.\n")
11918
0
SLANG_RAW("///\n")
11919
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
11920
0
SLANG_RAW("[__readNone]\n")
11921
0
SLANG_RAW("__glsl_version(450)\n")
11922
0
SLANG_RAW("__glsl_extension(GL_EXT_fragment_shader_barycentric)\n")
11923
0
SLANG_RAW("[require(glsl_hlsl_spirv, getattributeatvertex)]\n")
11924
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
11925
0
SLANG_RAW("vector<T,N> GetAttributeAtVertex(__constref vector<T,N> attribute, uint vertexIndex)\n")
11926
0
SLANG_RAW("{\n")
11927
0
SLANG_RAW("    __target_switch\n")
11928
0
SLANG_RAW("    {\n")
11929
0
SLANG_RAW("    case hlsl:\n")
11930
0
SLANG_RAW("        return __GetAttributeAtVertex(__ResolveVaryingInputRef(attribute), vertexIndex);\n")
11931
0
SLANG_RAW("    case glsl:\n")
11932
0
SLANG_RAW("    case spirv:\n")
11933
0
SLANG_RAW("        return __GetPerVertexInputArray(__ResolveVaryingInputRef(attribute))[vertexIndex];\n")
11934
0
SLANG_RAW("    }\n")
11935
0
SLANG_RAW("}\n")
11936
0
SLANG_RAW("\n")
11937
0
SLANG_RAW("/// Get the value of a vertex attribute at a specific vertex.\n")
11938
0
SLANG_RAW("///\n")
11939
0
SLANG_RAW("/// The `GetAttributeAtVertex()` function can be used in a fragment shader\n")
11940
0
SLANG_RAW("/// to get the value of the given `attribute` at the vertex of the primitive\n")
11941
0
SLANG_RAW("/// that corresponds to the given `vertexIndex`.\n")
11942
0
SLANG_RAW("///\n")
11943
0
SLANG_RAW("/// Note that the `attribute` must have been a declared varying input to\n")
11944
0
SLANG_RAW("/// the fragment shader with the `nointerpolation` modifier.\n")
11945
0
SLANG_RAW("///\n")
11946
0
SLANG_RAW("/// This function can be applied to scalars, vectors, and matrices of\n")
11947
0
SLANG_RAW("/// built-in scalar types.\n")
11948
0
SLANG_RAW("///\n")
11949
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
11950
0
SLANG_RAW("[__readNone]\n")
11951
0
SLANG_RAW("__glsl_version(450)\n")
11952
0
SLANG_RAW("__glsl_extension(GL_EXT_fragment_shader_barycentric)\n")
11953
0
SLANG_RAW("[require(glsl_hlsl_spirv, getattributeatvertex)]\n")
11954
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
11955
0
SLANG_RAW("matrix<T,N,M> GetAttributeAtVertex(__constref matrix<T,N,M> attribute, uint vertexIndex)\n")
11956
0
SLANG_RAW("{\n")
11957
0
SLANG_RAW("    __target_switch\n")
11958
0
SLANG_RAW("    {\n")
11959
0
SLANG_RAW("    case hlsl:\n")
11960
0
SLANG_RAW("        return __GetAttributeAtVertex(__ResolveVaryingInputRef(attribute), vertexIndex);\n")
11961
0
SLANG_RAW("    case glsl:\n")
11962
0
SLANG_RAW("    case spirv:\n")
11963
0
SLANG_RAW("        return __GetPerVertexInputArray(__ResolveVaryingInputRef(attribute))[vertexIndex];\n")
11964
0
SLANG_RAW("    }\n")
11965
0
SLANG_RAW("}\n")
11966
0
SLANG_RAW("\n")
11967
0
SLANG_RAW("// Get number of samples in render target\n")
11968
0
SLANG_RAW("[__readNone]\n")
11969
0
SLANG_RAW("[require(hlsl, sm_4_0)]\n")
11970
0
SLANG_RAW("[require(metal)]\n")
11971
0
SLANG_RAW("uint GetRenderTargetSampleCount()\n")
11972
0
SLANG_RAW("{\n")
11973
0
SLANG_RAW("    __target_switch\n")
11974
0
SLANG_RAW("    {\n")
11975
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GetRenderTargetSampleCount\";\n")
11976
0
SLANG_RAW("    case metal: __intrinsic_asm \"get_num_samples\";\n")
11977
0
SLANG_RAW("    }\n")
11978
0
SLANG_RAW("}\n")
11979
0
SLANG_RAW("\n")
11980
0
SLANG_RAW("// Get position of given sample\n")
11981
0
SLANG_RAW("[__readNone]\n")
11982
0
SLANG_RAW("[require(hlsl, sm_4_0)]\n")
11983
0
SLANG_RAW("[require(metal)]\n")
11984
0
SLANG_RAW("float2 GetRenderTargetSamplePosition(int Index)\n")
11985
0
SLANG_RAW("{\n")
11986
0
SLANG_RAW("    __target_switch\n")
11987
0
SLANG_RAW("    {\n")
11988
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GetRenderTargetSamplePosition\";\n")
11989
0
SLANG_RAW("    case metal: __intrinsic_asm \"get_sample_position\";\n")
11990
0
SLANG_RAW("    }\n")
11991
0
SLANG_RAW("}\n")
11992
0
SLANG_RAW("\n")
11993
0
SLANG_RAW("/// Group memory barrier. Ensures that all memory accesses in the group are visible to all threads in the group.\n")
11994
0
SLANG_RAW("/// @category barrier\n")
11995
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
11996
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
11997
0
SLANG_RAW("void GroupMemoryBarrier()\n")
11998
0
SLANG_RAW("{\n")
11999
0
SLANG_RAW("    __target_switch\n")
12000
0
SLANG_RAW("    {\n")
12001
0
SLANG_RAW("    case glsl: __intrinsic_asm \"memoryBarrier(gl_ScopeWorkgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease)\";\n")
12002
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GroupMemoryBarrier\";\n")
12003
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__threadfence_block\";\n")
12004
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_threadgroup)\";\n")
12005
0
SLANG_RAW("    case spirv:\n")
12006
0
SLANG_RAW("        spirv_asm\n")
12007
0
SLANG_RAW("        {\n")
12008
0
SLANG_RAW("            OpMemoryBarrier Workgroup AcquireRelease|WorkgroupMemory\n")
12009
0
SLANG_RAW("        };\n")
12010
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"workgroupBarrier\";\n")
12011
0
SLANG_RAW("    }\n")
12012
0
SLANG_RAW("}\n")
12013
0
SLANG_RAW("\n")
12014
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, memorybarrier)]\n")
12015
0
SLANG_RAW("void __subgroupBarrier()\n")
12016
0
SLANG_RAW("{\n")
12017
0
SLANG_RAW("    __target_switch\n")
12018
0
SLANG_RAW("    {\n")
12019
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBarrier\";\n")
12020
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GroupMemoryBarrierWithGroupSync\";\n")
12021
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__syncthreads()\";\n")
12022
0
SLANG_RAW("    case metal: __intrinsic_asm \"simdgroup_barrier(mem_flags::none)\";\n")
12023
0
SLANG_RAW("    case spirv:\n")
12024
0
SLANG_RAW("        spirv_asm\n")
12025
0
SLANG_RAW("        {\n")
12026
0
SLANG_RAW("            OpControlBarrier Subgroup Subgroup AcquireRelease|WorkgroupMemory|ImageMemory|UniformMemory\n")
12027
0
SLANG_RAW("        };\n")
12028
0
SLANG_RAW("    }\n")
12029
0
SLANG_RAW("}\n")
12030
0
SLANG_RAW("\n")
12031
0
SLANG_RAW("/// Group memory barrier. Ensures that all memory accesses in the group are visible to all threads in the group.\n")
12032
0
SLANG_RAW("/// @category barrier\n")
12033
0
SLANG_RAW("__glsl_extension(GL_KHR_memory_scope_semantics)\n")
12034
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, memorybarrier)]\n")
12035
0
SLANG_RAW("void GroupMemoryBarrierWithGroupSync()\n")
12036
0
SLANG_RAW("{\n")
12037
0
SLANG_RAW("    __target_switch\n")
12038
0
SLANG_RAW("    {\n")
12039
0
SLANG_RAW("    case glsl: __intrinsic_asm \"controlBarrier(gl_ScopeWorkgroup, gl_ScopeWorkgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease)\";\n")
12040
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GroupMemoryBarrierWithGroupSync\";\n")
12041
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__syncthreads()\";\n")
12042
0
SLANG_RAW("    case metal: __intrinsic_asm \"threadgroup_barrier(mem_flags::mem_threadgroup)\";\n")
12043
0
SLANG_RAW("    case spirv:\n")
12044
0
SLANG_RAW("        spirv_asm\n")
12045
0
SLANG_RAW("        {\n")
12046
0
SLANG_RAW("            OpControlBarrier Workgroup Workgroup AcquireRelease|WorkgroupMemory\n")
12047
0
SLANG_RAW("        };\n")
12048
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"workgroupBarrier\";\n")
12049
0
SLANG_RAW("    }\n")
12050
0
SLANG_RAW("}\n")
12051
0
SLANG_RAW("\n")
12052
0
SLANG_RAW("// Atomics\n")
12053
0
SLANG_RAW("\n")
12054
0
SLANG_RAW("// Accepts an ImageSubscript\n")
12055
0
SLANG_RAW("// Gets Texture used with ImageSubscript.\n")
12056
0
SLANG_RAW("__generic<TextureAccess>\n")
12057
0
SLANG_RAW("__intrinsic_op(")
12058
0
SLANG_SPLICE(kIROp_ExtractTextureFromTextureAccess
12059
0
)
12060
0
SLANG_RAW(")\n")
12061
0
SLANG_RAW("TextureAccess* __extractTextureFromTextureAccess(__ref TextureAccess x);\n")
12062
0
SLANG_RAW("\n")
12063
0
SLANG_RAW("// Accepts an ImageSubscript\n")
12064
0
SLANG_RAW("// Gets Coord from ImageSubscript. Swizzles out ArrayCoord if applicable\n")
12065
0
SLANG_RAW("__generic<TextureAccess>\n")
12066
0
SLANG_RAW("__intrinsic_op(")
12067
0
SLANG_SPLICE(kIROp_ExtractCoordFromTextureAccess
12068
0
)
12069
0
SLANG_RAW(")\n")
12070
0
SLANG_RAW("uint __extractCoordFromTextureAccess(__ref TextureAccess x);\n")
12071
0
SLANG_RAW("\n")
12072
0
SLANG_RAW("// Accepts an ImageSubscript\n")
12073
0
SLANG_RAW("// Gets ArrayCoord from ImageSubscript\n")
12074
0
SLANG_RAW("__generic<TextureAccess>\n")
12075
0
SLANG_RAW("__intrinsic_op(")
12076
0
SLANG_SPLICE(kIROp_ExtractArrayCoordFromTextureAccess
12077
0
)
12078
0
SLANG_RAW(")\n")
12079
0
SLANG_RAW("uint __extractArrayCoordFromTextureAccess(__ref TextureAccess x);\n")
12080
0
SLANG_RAW("\n")
12081
12082
// Generates code for:
12083
// InterlockedAdd, InterlockedAnd, InterlockedOr, InterlockedXor,
12084
// InterlockedMax, InterlockedMin, InterlockedExchange
12085
0
struct SlangAtomicOperationInfo
12086
0
{
12087
0
    const char* slangCallSuffix;
12088
0
    const char* internalCallSuffix;
12089
0
    const char* interface;
12090
0
};
12091
12092
0
SlangAtomicOperationInfo slangAtomicOperationInfo[7] = {
12093
0
    { "Add", "add", "IArithmeticAtomicable" },
12094
0
    { "And", "and", "IArithmeticAtomicable" },
12095
0
    { "Or", "or", "IArithmeticAtomicable" },
12096
0
    { "Xor", "xor", "IArithmeticAtomicable" },
12097
0
    { "Max", "max", "IArithmeticAtomicable" },
12098
0
    { "Min", "min", "IArithmeticAtomicable" },
12099
0
    { "Exchange", "exchange", "IAtomicable" },
12100
0
};
12101
12102
0
for (SlangAtomicOperationInfo atomicOp : slangAtomicOperationInfo)
12103
0
{
12104
0
SLANG_RAW("#line 10685 \"hlsl.meta.slang\"")
12105
0
SLANG_RAW("\n")
12106
0
SLANG_RAW("\n")
12107
0
SLANG_RAW("/// Perform an atomic ")
12108
0
SLANG_SPLICE(atomicOp.internalCallSuffix
12109
0
)
12110
0
SLANG_RAW(" operation on `dest`.\n")
12111
0
SLANG_RAW("/// @param T The type of the value to perform the atomic operation on.\n")
12112
0
SLANG_RAW("/// @param dest The value to perform the atomic operation on.\n")
12113
0
SLANG_RAW("/// @param value The operand to the atomic operation.\n")
12114
0
SLANG_RAW("/// @param original_value The value of `dest` before the operation.\n")
12115
0
SLANG_RAW("/// @remarks When targeting HLSL, it is invalid to call this function with `T` being a floating-point type, since\n")
12116
0
SLANG_RAW("/// HLSL does not allow atomic operations on floating point types. For `InterlockedAdd`, consider using\n")
12117
0
SLANG_RAW("/// `RWByteAddressBuffer.InterlockedAddF32` or `RWByteAddressBuffer.InterlockedAddF16` instead when NVAPI is available.\n")
12118
0
SLANG_RAW("/// On SPIR-V (Vulkan), all integer and floating point types are supported.\n")
12119
0
SLANG_RAW("/// On Metal and WGSL, all floating-point types are not supported.\n")
12120
0
SLANG_RAW("/// @category atomic Atomic functions\n")
12121
0
SLANG_RAW("[ForceInline]\n")
12122
0
SLANG_RAW("__glsl_version(430)\n")
12123
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
12124
0
SLANG_RAW("void Interlocked")
12125
0
SLANG_SPLICE(atomicOp.slangCallSuffix
12126
0
)
12127
0
SLANG_RAW("<T:")
12128
0
SLANG_SPLICE(atomicOp.interface
12129
0
)
12130
0
SLANG_RAW(">(__ref T dest,  T value)\n")
12131
0
SLANG_RAW("{\n")
12132
0
SLANG_RAW("    __atomic_")
12133
0
SLANG_SPLICE(atomicOp.internalCallSuffix
12134
0
)
12135
0
SLANG_RAW("(dest, value);\n")
12136
0
SLANG_RAW("}\n")
12137
0
SLANG_RAW("\n")
12138
0
SLANG_RAW("[ForceInline]\n")
12139
0
SLANG_RAW("__glsl_version(430)\n")
12140
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
12141
0
SLANG_RAW("void Interlocked")
12142
0
SLANG_SPLICE(atomicOp.slangCallSuffix
12143
0
)
12144
0
SLANG_RAW("<T:")
12145
0
SLANG_SPLICE(atomicOp.interface
12146
0
)
12147
0
SLANG_RAW(">(__ref T dest, T value, out T original_value)\n")
12148
0
SLANG_RAW("{\n")
12149
0
SLANG_RAW("    original_value = __atomic_")
12150
0
SLANG_SPLICE(atomicOp.internalCallSuffix
12151
0
)
12152
0
SLANG_RAW("(dest, value);\n")
12153
0
SLANG_RAW("}\n")
12154
0
SLANG_RAW("\n")
12155
0
SLANG_RAW("[ForceInline]\n")
12156
0
SLANG_RAW("__glsl_version(430)\n")
12157
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
12158
0
SLANG_RAW("void Interlocked")
12159
0
SLANG_SPLICE(atomicOp.slangCallSuffix
12160
0
)
12161
0
SLANG_RAW("(__ref uint dest, int value)\n")
12162
0
SLANG_RAW("{\n")
12163
0
SLANG_RAW("    __atomic_")
12164
0
SLANG_SPLICE(atomicOp.internalCallSuffix
12165
0
)
12166
0
SLANG_RAW("(dest, (uint)value);\n")
12167
0
SLANG_RAW("}\n")
12168
0
SLANG_RAW("\n")
12169
12170
0
} // for (SlangAtomicOperationInfo atomicOp : slangAtomicOperationInfo)
12171
0
SLANG_RAW("#line 10724 \"hlsl.meta.slang\"")
12172
0
SLANG_RAW("\n")
12173
0
SLANG_RAW("\n")
12174
0
SLANG_RAW("/// Perform an atomic compare and exchange operation on `dest`.\n")
12175
0
SLANG_RAW("/// @param T The type of the value to perform the atomic operation on.\n")
12176
0
SLANG_RAW("/// @param dest The value to perform the atomic operation on.\n")
12177
0
SLANG_RAW("/// @param compare_value The value to compare `dest` with.\n")
12178
0
SLANG_RAW("/// @param value The value to store into `dest` if the compare result is equal.\n")
12179
0
SLANG_RAW("/// @param original_value The value of `dest` before the operation.\n")
12180
0
SLANG_RAW("/// @remarks When targeting HLSL, a call to this function with `T` being `float` will translate to a call to\n")
12181
0
SLANG_RAW("/// `InterlockedCompareExchangeFloatBitwise`, which means the comparison is done as a bitwise comparison.\n")
12182
0
SLANG_RAW("///\n")
12183
0
SLANG_RAW("/// On SPIR-V (Vulkan), this function maps to `OpAtomicCompareExchange`.\n")
12184
0
SLANG_RAW("///\n")
12185
0
SLANG_RAW("/// On Metal and WGSL, all floating-point types are not supported.\n")
12186
0
SLANG_RAW("///\n")
12187
0
SLANG_RAW("/// On CUDA, this function maps to `atomicCAS`.\n")
12188
0
SLANG_RAW("/// @category atomic\n")
12189
0
SLANG_RAW("[ForceInline]\n")
12190
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
12191
0
SLANG_RAW("void InterlockedCompareExchange<T:IAtomicable>(__ref T dest, T compare_value, T value, out T original_value)\n")
12192
0
SLANG_RAW("{\n")
12193
0
SLANG_RAW("    original_value = __atomic_compare_exchange(dest, compare_value, value);\n")
12194
0
SLANG_RAW("}\n")
12195
0
SLANG_RAW("\n")
12196
0
SLANG_RAW("/// Perform an atomic compare and exchange operation on `dest`.\n")
12197
0
SLANG_RAW("/// @param T The type of the value to perform the atomic operation on.\n")
12198
0
SLANG_RAW("/// @param dest The value to perform the atomic operation on.\n")
12199
0
SLANG_RAW("/// @param compare_value The value to compare `dest` with.\n")
12200
0
SLANG_RAW("/// @param value The value to store into `dest` if the compare result is equal.\n")
12201
0
SLANG_RAW("/// @param original_value The value of `dest` before the operation.\n")
12202
0
SLANG_RAW("/// @remarks When targeting HLSL, a call to this function will translate to a call to\n")
12203
0
SLANG_RAW("/// `InterlockedCompareExchangeFloatBitwise`, which means the comparison is done as a bitwise comparison.\n")
12204
0
SLANG_RAW("///\n")
12205
0
SLANG_RAW("/// On SPIR-V (Vulkan), this function maps to `OpAtomicCompareExchange`.\n")
12206
0
SLANG_RAW("///\n")
12207
0
SLANG_RAW("/// On Metal and WGSL, this function is not available.\n")
12208
0
SLANG_RAW("///\n")
12209
0
SLANG_RAW("/// On CUDA, this function maps to `atomicCAS`.\n")
12210
0
SLANG_RAW("/// @category atomic\n")
12211
0
SLANG_RAW("[ForceInline]\n")
12212
0
SLANG_RAW("void InterlockedCompareExchangeFloatBitwise(__ref  float dest, float compare_value, float value)\n")
12213
0
SLANG_RAW("{\n")
12214
0
SLANG_RAW("    __atomic_compare_exchange(dest, compare_value, value);\n")
12215
0
SLANG_RAW("}\n")
12216
0
SLANG_RAW("\n")
12217
0
SLANG_RAW("[ForceInline]\n")
12218
0
SLANG_RAW("void InterlockedCompareExchangeFloatBitwise(__ref  float dest, float compare_value, float value, out float original_value)\n")
12219
0
SLANG_RAW("{\n")
12220
0
SLANG_RAW("    original_value = __atomic_compare_exchange(dest, compare_value, value);\n")
12221
0
SLANG_RAW("}\n")
12222
0
SLANG_RAW("\n")
12223
0
SLANG_RAW("/// Perform an atomic compare and store operation on `dest`.\n")
12224
0
SLANG_RAW("/// @param T The type of the value to perform the atomic operation on.\n")
12225
0
SLANG_RAW("/// @param dest The value to perform the atomic operation on.\n")
12226
0
SLANG_RAW("/// @param compare_value The value to compare `dest` with.\n")
12227
0
SLANG_RAW("/// @param value The value to store into `dest` if the compare result is equal.\n")
12228
0
SLANG_RAW("/// @remarks When targeting HLSL, a call to this function with `T` being `float` will translate to a call to\n")
12229
0
SLANG_RAW("/// `InterlockedCompareStoreFloatBitwise`, which means the comparison is done as a bitwise comparison.\n")
12230
0
SLANG_RAW("///\n")
12231
0
SLANG_RAW("/// On SPIR-V (Vulkan), this function maps to `OpAtomicCompareExchange`.\n")
12232
0
SLANG_RAW("///\n")
12233
0
SLANG_RAW("/// On Metal and WGSL, this function is not available.\n")
12234
0
SLANG_RAW("///\n")
12235
0
SLANG_RAW("/// On CUDA, this function maps to `atomicCAS`.\n")
12236
0
SLANG_RAW("/// @category atomic\n")
12237
0
SLANG_RAW("[ForceInline]\n")
12238
0
SLANG_RAW("__glsl_version(430)\n")
12239
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, atomic_glsl_hlsl_cuda_metal)]\n")
12240
0
SLANG_RAW("void InterlockedCompareStore<T:IAtomicable>(__ref T dest,  T compare_value,  T value)\n")
12241
0
SLANG_RAW("{\n")
12242
0
SLANG_RAW("    __target_switch\n")
12243
0
SLANG_RAW("    {\n")
12244
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"InterlockedCompareStore\";\n")
12245
0
SLANG_RAW("    default:\n")
12246
0
SLANG_RAW("        __atomic_compare_exchange(dest, compare_value, value);\n")
12247
0
SLANG_RAW("        return;\n")
12248
0
SLANG_RAW("    }\n")
12249
0
SLANG_RAW("}\n")
12250
0
SLANG_RAW("\n")
12251
0
SLANG_RAW("/// Perform an atomic compare and store operation on `dest`.\n")
12252
0
SLANG_RAW("/// @param T The type of the value to perform the atomic operation on.\n")
12253
0
SLANG_RAW("/// @param dest The value to perform the atomic operation on.\n")
12254
0
SLANG_RAW("/// @param compare_value The value to compare `dest` with.\n")
12255
0
SLANG_RAW("/// @param value The value to store into `dest` if the compare result is equal.\n")
12256
0
SLANG_RAW("/// @remarks When targeting HLSL, a call to this function will translate to a call to\n")
12257
0
SLANG_RAW("/// `InterlockedCompareStoreFloatBitwise`, which means the comparison is done as a bitwise comparison.\n")
12258
0
SLANG_RAW("///\n")
12259
0
SLANG_RAW("/// On SPIR-V (Vulkan), this function maps to `OpAtomicCompareExchange`.\n")
12260
0
SLANG_RAW("///\n")
12261
0
SLANG_RAW("/// On Metal and WGSL, this function is not available.\n")
12262
0
SLANG_RAW("///\n")
12263
0
SLANG_RAW("/// On CUDA, this function maps to `atomicCAS`.\n")
12264
0
SLANG_RAW("/// @category atomic\n")
12265
0
SLANG_RAW("[ForceInline]\n")
12266
0
SLANG_RAW("void InterlockedCompareStoreFloatBitwise<T:IAtomicable>(__ref  T dest,  T compare_value, T value)\n")
12267
0
SLANG_RAW("{\n")
12268
0
SLANG_RAW("    __target_switch\n")
12269
0
SLANG_RAW("    {\n")
12270
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"InterlockedCompareStoreFloatBitwise\";\n")
12271
0
SLANG_RAW("    default:\n")
12272
0
SLANG_RAW("        __atomic_compare_exchange(dest, compare_value, value);\n")
12273
0
SLANG_RAW("        return;\n")
12274
0
SLANG_RAW("    }\n")
12275
0
SLANG_RAW("}\n")
12276
0
SLANG_RAW("\n")
12277
0
SLANG_RAW("\n")
12278
0
SLANG_RAW("/// Test if a floating-point value is finite.\n")
12279
0
SLANG_RAW("/// @param x The input value.\n")
12280
0
SLANG_RAW("/// @return `true` if `x` is finite, `false` otherwise.\n")
12281
0
SLANG_RAW("/// @category math\n")
12282
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12283
0
SLANG_RAW("[__readNone]\n")
12284
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12285
0
SLANG_RAW("bool isfinite(T x)\n")
12286
0
SLANG_RAW("{\n")
12287
0
SLANG_RAW("    __target_switch\n")
12288
0
SLANG_RAW("    {\n")
12289
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"isfinite\";\n")
12290
0
SLANG_RAW("    case cuda:\n")
12291
0
SLANG_RAW("    case cpp:\n")
12292
0
SLANG_RAW("        __intrinsic_asm \"$P_isfinite($0)\";\n")
12293
0
SLANG_RAW("    case metal:\n")
12294
0
SLANG_RAW("        __intrinsic_asm \"isfinite\";\n")
12295
0
SLANG_RAW("    default:\n")
12296
0
SLANG_RAW("        return !(isinf(x) || isnan(x));\n")
12297
0
SLANG_RAW("    }\n")
12298
0
SLANG_RAW("}\n")
12299
0
SLANG_RAW("\n")
12300
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12301
0
SLANG_RAW("[__readNone]\n")
12302
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12303
0
SLANG_RAW("vector<bool, N> isfinite(vector<T, N> x)\n")
12304
0
SLANG_RAW("{\n")
12305
0
SLANG_RAW("    __target_switch\n")
12306
0
SLANG_RAW("    {\n")
12307
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"isfinite\";\n")
12308
0
SLANG_RAW("    case glsl:\n")
12309
0
SLANG_RAW("    case spirv:\n")
12310
0
SLANG_RAW("        return !(isinf(x) || isnan(x));\n")
12311
0
SLANG_RAW("    case metal:\n")
12312
0
SLANG_RAW("        __intrinsic_asm \"isfinite\";\n")
12313
0
SLANG_RAW("    default:\n")
12314
0
SLANG_RAW("        VECTOR_MAP_UNARY(bool, N, isfinite, x);\n")
12315
0
SLANG_RAW("    }\n")
12316
0
SLANG_RAW("}\n")
12317
0
SLANG_RAW("\n")
12318
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12319
0
SLANG_RAW("[__readNone]\n")
12320
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12321
0
SLANG_RAW("matrix<bool, N, M> isfinite(matrix<T, N, M> x)\n")
12322
0
SLANG_RAW("{\n")
12323
0
SLANG_RAW("    __target_switch\n")
12324
0
SLANG_RAW("    {\n")
12325
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"isfinite\";\n")
12326
0
SLANG_RAW("    default:\n")
12327
0
SLANG_RAW("        MATRIX_MAP_UNARY(bool, N, M, isfinite, x);\n")
12328
0
SLANG_RAW("    }\n")
12329
0
SLANG_RAW("}\n")
12330
0
SLANG_RAW("\n")
12331
0
SLANG_RAW("/// Test if a floating-point value is infinite.\n")
12332
0
SLANG_RAW("/// @param x The input value.\n")
12333
0
SLANG_RAW("/// @return `true` if `x` is infinite, `false` otherwise.\n")
12334
0
SLANG_RAW("/// @category math\n")
12335
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12336
0
SLANG_RAW("[__readNone]\n")
12337
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12338
0
SLANG_RAW("bool isinf(T x)\n")
12339
0
SLANG_RAW("{\n")
12340
0
SLANG_RAW("    __target_switch\n")
12341
0
SLANG_RAW("    {\n")
12342
0
SLANG_RAW("    case hlsl:\n")
12343
0
SLANG_RAW("    case glsl:\n")
12344
0
SLANG_RAW("    case metal:\n")
12345
0
SLANG_RAW("        __intrinsic_asm \"isinf\";\n")
12346
0
SLANG_RAW("    case cuda:\n")
12347
0
SLANG_RAW("    case cpp:\n")
12348
0
SLANG_RAW("        __intrinsic_asm \"$P_isinf($0)\";\n")
12349
0
SLANG_RAW("    case spirv:\n")
12350
0
SLANG_RAW("        return spirv_asm { result:$$bool = OpIsInf $x};\n")
12351
0
SLANG_RAW("    case wgsl:\n")
12352
0
SLANG_RAW("        static_assert(T is float, \"isnan is implemented only for float type\");\n")
12353
0
SLANG_RAW("        if (let f = x as float)\n")
12354
0
SLANG_RAW("        {\n")
12355
0
SLANG_RAW("            let bits = asuint(f);\n")
12356
0
SLANG_RAW("            let exp = (bits >> 23) & 0xffu;\n")
12357
0
SLANG_RAW("            let frac = bits & 0x7fffffu;\n")
12358
0
SLANG_RAW("            return exp == 0xffu && frac == 0u;\n")
12359
0
SLANG_RAW("        }\n")
12360
0
SLANG_RAW("        return false;\n")
12361
0
SLANG_RAW("    }\n")
12362
0
SLANG_RAW("}\n")
12363
0
SLANG_RAW("\n")
12364
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12365
0
SLANG_RAW("[__readNone]\n")
12366
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12367
0
SLANG_RAW("vector<bool, N> isinf(vector<T, N> x)\n")
12368
0
SLANG_RAW("{\n")
12369
0
SLANG_RAW("    __target_switch\n")
12370
0
SLANG_RAW("    {\n")
12371
0
SLANG_RAW("    case hlsl:\n")
12372
0
SLANG_RAW("    case glsl:\n")
12373
0
SLANG_RAW("    case metal:\n")
12374
0
SLANG_RAW("        __intrinsic_asm \"isinf\";\n")
12375
0
SLANG_RAW("    case spirv:\n")
12376
0
SLANG_RAW("        return spirv_asm { result:$$vector<bool,N> = OpIsInf $x};\n")
12377
0
SLANG_RAW("    default:\n")
12378
0
SLANG_RAW("        VECTOR_MAP_UNARY(bool, N, isinf, x);\n")
12379
0
SLANG_RAW("    }\n")
12380
0
SLANG_RAW("}\n")
12381
0
SLANG_RAW("\n")
12382
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12383
0
SLANG_RAW("[__readNone]\n")
12384
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12385
0
SLANG_RAW("matrix<bool, N, M> isinf(matrix<T, N, M> x)\n")
12386
0
SLANG_RAW("{\n")
12387
0
SLANG_RAW("    __target_switch\n")
12388
0
SLANG_RAW("    {\n")
12389
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"isinf\";\n")
12390
0
SLANG_RAW("    default:\n")
12391
0
SLANG_RAW("        MATRIX_MAP_UNARY(bool, N, M, isinf, x);\n")
12392
0
SLANG_RAW("    }\n")
12393
0
SLANG_RAW("}\n")
12394
0
SLANG_RAW("\n")
12395
0
SLANG_RAW("/// Test if a floating-point value is not-a-number.\n")
12396
0
SLANG_RAW("/// @param x The input value.\n")
12397
0
SLANG_RAW("/// @return `true` if `x` is not-a-number, `false` otherwise.\n")
12398
0
SLANG_RAW("/// @category math\n")
12399
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12400
0
SLANG_RAW("[__readNone]\n")
12401
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12402
0
SLANG_RAW("bool isnan(T x)\n")
12403
0
SLANG_RAW("{\n")
12404
0
SLANG_RAW("    __target_switch\n")
12405
0
SLANG_RAW("    {\n")
12406
0
SLANG_RAW("    case hlsl:\n")
12407
0
SLANG_RAW("    case glsl:\n")
12408
0
SLANG_RAW("    case metal:\n")
12409
0
SLANG_RAW("        __intrinsic_asm \"isnan\";\n")
12410
0
SLANG_RAW("    case cuda:\n")
12411
0
SLANG_RAW("    case cpp:\n")
12412
0
SLANG_RAW("        __intrinsic_asm \"$P_isnan($0)\";\n")
12413
0
SLANG_RAW("    case spirv:\n")
12414
0
SLANG_RAW("        return spirv_asm { result:$$bool = OpIsNan $x};\n")
12415
0
SLANG_RAW("    case wgsl:\n")
12416
0
SLANG_RAW("        static_assert(T is float, \"isnan is implemented only for float type\");\n")
12417
0
SLANG_RAW("        if (let f = x as float)\n")
12418
0
SLANG_RAW("        {\n")
12419
0
SLANG_RAW("            let bits = asuint(f);\n")
12420
0
SLANG_RAW("            let exp = (bits >> 23) & 0xffu;\n")
12421
0
SLANG_RAW("            let frac = bits & 0x7fffffu;\n")
12422
0
SLANG_RAW("            return exp == 0xffu && frac != 0u;\n")
12423
0
SLANG_RAW("        }\n")
12424
0
SLANG_RAW("        return false;\n")
12425
0
SLANG_RAW("    }\n")
12426
0
SLANG_RAW("}\n")
12427
0
SLANG_RAW("\n")
12428
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12429
0
SLANG_RAW("[__readNone]\n")
12430
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12431
0
SLANG_RAW("vector<bool, N> isnan(vector<T, N> x)\n")
12432
0
SLANG_RAW("{\n")
12433
0
SLANG_RAW("    __target_switch\n")
12434
0
SLANG_RAW("    {\n")
12435
0
SLANG_RAW("    case hlsl:\n")
12436
0
SLANG_RAW("    case glsl:\n")
12437
0
SLANG_RAW("    case metal:\n")
12438
0
SLANG_RAW("        __intrinsic_asm \"isnan\";\n")
12439
0
SLANG_RAW("    case spirv:\n")
12440
0
SLANG_RAW("        return spirv_asm { result:$$vector<bool, N> = OpIsNan $x};\n")
12441
0
SLANG_RAW("    default:\n")
12442
0
SLANG_RAW("        VECTOR_MAP_UNARY(bool, N, isnan, x);\n")
12443
0
SLANG_RAW("    }\n")
12444
0
SLANG_RAW("}\n")
12445
0
SLANG_RAW("\n")
12446
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12447
0
SLANG_RAW("[__readNone]\n")
12448
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12449
0
SLANG_RAW("matrix<bool, N, M> isnan(matrix<T, N, M> x)\n")
12450
0
SLANG_RAW("{\n")
12451
0
SLANG_RAW("    __target_switch\n")
12452
0
SLANG_RAW("    {\n")
12453
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"isnan\";\n")
12454
0
SLANG_RAW("    default:\n")
12455
0
SLANG_RAW("        MATRIX_MAP_UNARY(bool, N, M, isnan, x);\n")
12456
0
SLANG_RAW("    }\n")
12457
0
SLANG_RAW("}\n")
12458
0
SLANG_RAW("\n")
12459
0
SLANG_RAW("/// Construct float from mantissa and exponent.\n")
12460
0
SLANG_RAW("/// @param x The significand.\n")
12461
0
SLANG_RAW("/// @param exp The exponent.\n")
12462
0
SLANG_RAW("/// @return The floating-point number constructed from `x` and `exp`.\n")
12463
0
SLANG_RAW("/// @category math\n")
12464
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12465
0
SLANG_RAW("[__readNone]\n")
12466
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12467
0
SLANG_RAW("T ldexp(T x, T exp)\n")
12468
0
SLANG_RAW("{\n")
12469
0
SLANG_RAW("    __target_switch\n")
12470
0
SLANG_RAW("    {\n")
12471
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ldexp\";\n")
12472
0
SLANG_RAW("    // In WGSL spec, ldexp can only take integer as the exponent.\n")
12473
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($0 * exp2($1))\";\n")
12474
0
SLANG_RAW("    default:\n")
12475
0
SLANG_RAW("        return x * exp2(exp);\n")
12476
0
SLANG_RAW("    }\n")
12477
0
SLANG_RAW("}\n")
12478
0
SLANG_RAW("\n")
12479
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12480
0
SLANG_RAW("[__readNone]\n")
12481
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12482
0
SLANG_RAW("vector<T, N> ldexp(vector<T, N> x, vector<T, N> exp)\n")
12483
0
SLANG_RAW("{\n")
12484
0
SLANG_RAW("    __target_switch\n")
12485
0
SLANG_RAW("    {\n")
12486
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ldexp\";\n")
12487
0
SLANG_RAW("    // In WGSL spec, ldexp can only take integer as the exponent.\n")
12488
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($0 * exp2($1))\";\n")
12489
0
SLANG_RAW("    default:\n")
12490
0
SLANG_RAW("        return x * exp2(exp);\n")
12491
0
SLANG_RAW("    }\n")
12492
0
SLANG_RAW("}\n")
12493
0
SLANG_RAW("\n")
12494
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12495
0
SLANG_RAW("[__readNone]\n")
12496
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12497
0
SLANG_RAW("matrix<T, N, M> ldexp(matrix<T, N, M> x, matrix<T, N, M> exp)\n")
12498
0
SLANG_RAW("{\n")
12499
0
SLANG_RAW("    __target_switch\n")
12500
0
SLANG_RAW("    {\n")
12501
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ldexp\";\n")
12502
0
SLANG_RAW("    default:\n")
12503
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, ldexp, x, exp);\n")
12504
0
SLANG_RAW("    }\n")
12505
0
SLANG_RAW("}\n")
12506
0
SLANG_RAW("\n")
12507
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, E : __BuiltinIntegerType>\n")
12508
0
SLANG_RAW("[__readNone]\n")
12509
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12510
0
SLANG_RAW("T ldexp(T x, E exp)\n")
12511
0
SLANG_RAW("{\n")
12512
0
SLANG_RAW("    __target_switch\n")
12513
0
SLANG_RAW("    {\n")
12514
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ldexp\";\n")
12515
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ldexp\";\n")
12516
0
SLANG_RAW("    case metal: __intrinsic_asm \"ldexp\";\n")
12517
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12518
0
SLANG_RAW("        OpExtInst $$T result glsl450 Ldexp $x $exp\n")
12519
0
SLANG_RAW("    };\n")
12520
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"ldexp\";\n")
12521
0
SLANG_RAW("    default:\n")
12522
0
SLANG_RAW("        return ldexp(x, __realCast<T>(exp));\n")
12523
0
SLANG_RAW("    }\n")
12524
0
SLANG_RAW("}\n")
12525
0
SLANG_RAW("\n")
12526
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, E : __BuiltinIntegerType, let N : int>\n")
12527
0
SLANG_RAW("[__readNone]\n")
12528
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12529
0
SLANG_RAW("vector<T, N> ldexp(vector<T, N> x, vector<E, N> exp)\n")
12530
0
SLANG_RAW("{\n")
12531
0
SLANG_RAW("    __target_switch\n")
12532
0
SLANG_RAW("    {\n")
12533
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ldexp\";\n")
12534
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"ldexp\";\n")
12535
0
SLANG_RAW("    case metal: __intrinsic_asm \"ldexp\";\n")
12536
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12537
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Ldexp $x $exp\n")
12538
0
SLANG_RAW("    };\n")
12539
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"ldexp\";\n")
12540
0
SLANG_RAW("    default:\n")
12541
0
SLANG_RAW("        vector<T,N> temp;\n")
12542
0
SLANG_RAW("        [ForceUnroll]\n")
12543
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
12544
0
SLANG_RAW("            temp[i] = __realCast<T>(exp[i]);\n")
12545
0
SLANG_RAW("        return ldexp(x, temp);\n")
12546
0
SLANG_RAW("    }\n")
12547
0
SLANG_RAW("}\n")
12548
0
SLANG_RAW("\n")
12549
0
SLANG_RAW("\n")
12550
0
SLANG_RAW("/// Compute the length of a vector.\n")
12551
0
SLANG_RAW("/// @param x The input vector.\n")
12552
0
SLANG_RAW("/// @return The length of `x`.\n")
12553
0
SLANG_RAW("/// @category math\n")
12554
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12555
0
SLANG_RAW("[__readNone]\n")
12556
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12557
0
SLANG_RAW("T length(vector<T, N> x)\n")
12558
0
SLANG_RAW("{\n")
12559
0
SLANG_RAW("    __target_switch\n")
12560
0
SLANG_RAW("    {\n")
12561
0
SLANG_RAW("    case glsl: __intrinsic_asm \"length\";\n")
12562
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"length\";\n")
12563
0
SLANG_RAW("    case metal: __intrinsic_asm \"length\";\n")
12564
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12565
0
SLANG_RAW("        OpExtInst $$T result glsl450 Length $x\n")
12566
0
SLANG_RAW("    };\n")
12567
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"length\";\n")
12568
0
SLANG_RAW("    default:\n")
12569
0
SLANG_RAW("        return sqrt(dot(x, x));\n")
12570
0
SLANG_RAW("    }\n")
12571
0
SLANG_RAW("}\n")
12572
0
SLANG_RAW("\n")
12573
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12574
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12575
0
SLANG_RAW("T length(T x)\n")
12576
0
SLANG_RAW("{\n")
12577
0
SLANG_RAW("    __target_switch\n")
12578
0
SLANG_RAW("    {\n")
12579
0
SLANG_RAW("    case glsl: __intrinsic_asm \"length\";\n")
12580
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12581
0
SLANG_RAW("        OpExtInst $$T result glsl450 Length $x\n")
12582
0
SLANG_RAW("    };\n")
12583
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"length\";\n")
12584
0
SLANG_RAW("    default:\n")
12585
0
SLANG_RAW("        return abs(x);\n")
12586
0
SLANG_RAW("    }\n")
12587
0
SLANG_RAW("}\n")
12588
0
SLANG_RAW("\n")
12589
0
SLANG_RAW("/// Computes linear interpolation.\n")
12590
0
SLANG_RAW("/// @param x The starting value.\n")
12591
0
SLANG_RAW("/// @param y The ending value.\n")
12592
0
SLANG_RAW("/// @param s The interpolation factor.\n")
12593
0
SLANG_RAW("/// @return Returns `x+(y-x)*s`.\n")
12594
0
SLANG_RAW("/// @category math\n")
12595
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12596
0
SLANG_RAW("[__readNone]\n")
12597
0
SLANG_RAW("T lerp(T x, T y, T s)\n")
12598
0
SLANG_RAW("{\n")
12599
0
SLANG_RAW("    __target_switch\n")
12600
0
SLANG_RAW("    {\n")
12601
0
SLANG_RAW("    case glsl: __intrinsic_asm \"mix\";\n")
12602
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"mix\";\n")
12603
0
SLANG_RAW("    case metal: __intrinsic_asm \"mix\";\n")
12604
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"lerp\";\n")
12605
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12606
0
SLANG_RAW("        OpExtInst $$T result glsl450 FMix $x $y $s\n")
12607
0
SLANG_RAW("    };\n")
12608
0
SLANG_RAW("    default:\n")
12609
0
SLANG_RAW("        return x + (y - x) * s;\n")
12610
0
SLANG_RAW("    }\n")
12611
0
SLANG_RAW("}\n")
12612
0
SLANG_RAW("\n")
12613
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12614
0
SLANG_RAW("[__readNone]\n")
12615
0
SLANG_RAW("vector<T, N> lerp(vector<T, N> x, vector<T, N> y, vector<T, N> s)\n")
12616
0
SLANG_RAW("{\n")
12617
0
SLANG_RAW("    __target_switch\n")
12618
0
SLANG_RAW("    {\n")
12619
0
SLANG_RAW("    case glsl: __intrinsic_asm \"mix\";\n")
12620
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"mix\";\n")
12621
0
SLANG_RAW("    case metal: __intrinsic_asm \"mix\";\n")
12622
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"lerp\";\n")
12623
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12624
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 FMix $x $y $s\n")
12625
0
SLANG_RAW("    };\n")
12626
0
SLANG_RAW("    default:\n")
12627
0
SLANG_RAW("        return x + (y - x) * s;\n")
12628
0
SLANG_RAW("    }\n")
12629
0
SLANG_RAW("}\n")
12630
0
SLANG_RAW("\n")
12631
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12632
0
SLANG_RAW("[__readNone]\n")
12633
0
SLANG_RAW("matrix<T,N,M> lerp(matrix<T,N,M> x, matrix<T,N,M> y, matrix<T,N,M> s)\n")
12634
0
SLANG_RAW("{\n")
12635
0
SLANG_RAW("    __target_switch\n")
12636
0
SLANG_RAW("    {\n")
12637
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"lerp\";\n")
12638
0
SLANG_RAW("    default:\n")
12639
0
SLANG_RAW("        MATRIX_MAP_TRINARY(T, N, M, lerp, x, y, s);\n")
12640
0
SLANG_RAW("    }\n")
12641
0
SLANG_RAW("}\n")
12642
0
SLANG_RAW("\n")
12643
0
SLANG_RAW("/// Legacy lighting function (obsolete).\n")
12644
0
SLANG_RAW("/// @param n_dot_l The dot product of the normal and light vectors.\n")
12645
0
SLANG_RAW("/// @param n_dot_h The dot product of the normal and half-angle vectors.\n")
12646
0
SLANG_RAW("/// @param m The material shininess factor.\n")
12647
0
SLANG_RAW("/// @return The lighting coefficients, (ambient, diffuse, specular, 1.0).\n")
12648
0
SLANG_RAW("/// @remarks In HLSL, this function is implemented as an intrinsic. It is emulated for other targets.\n")
12649
0
SLANG_RAW("/// @deprecated\n")
12650
0
SLANG_RAW("/// @category math\n")
12651
0
SLANG_RAW("[__readNone]\n")
12652
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
12653
0
SLANG_RAW("float4 lit(float n_dot_l, float n_dot_h, float m)\n")
12654
0
SLANG_RAW("{\n")
12655
0
SLANG_RAW("    __target_switch\n")
12656
0
SLANG_RAW("    {\n")
12657
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"lit\";\n")
12658
0
SLANG_RAW("    default:\n")
12659
0
SLANG_RAW("        let ambient = 1.0f;\n")
12660
0
SLANG_RAW("        let diffuse = max(n_dot_l, 0.0f);\n")
12661
0
SLANG_RAW("        let specular = step(0.0f, n_dot_l) * max(pow(n_dot_h, m), 0.0f);\n")
12662
0
SLANG_RAW("        return float4(ambient, diffuse, specular, 1.0f);\n")
12663
0
SLANG_RAW("    }\n")
12664
0
SLANG_RAW("}\n")
12665
0
SLANG_RAW("\n")
12666
0
SLANG_RAW("/// Compute base-e logarithm.\n")
12667
0
SLANG_RAW("/// @param x The input value.\n")
12668
0
SLANG_RAW("/// @return The natural logarithm of `x`.\n")
12669
0
SLANG_RAW("/// @category math\n")
12670
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12671
0
SLANG_RAW("[__readNone]\n")
12672
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12673
0
SLANG_RAW("T log(T x)\n")
12674
0
SLANG_RAW("{\n")
12675
0
SLANG_RAW("    __target_switch\n")
12676
0
SLANG_RAW("    {\n")
12677
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_log($0)\";\n")
12678
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_log($0)\";\n")
12679
0
SLANG_RAW("    case glsl: __intrinsic_asm \"log\";\n")
12680
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log\";\n")
12681
0
SLANG_RAW("    case metal: __intrinsic_asm \"log\";\n")
12682
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12683
0
SLANG_RAW("        OpExtInst $$T result glsl450 Log $x\n")
12684
0
SLANG_RAW("    };\n")
12685
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"log\";\n")
12686
0
SLANG_RAW("    }\n")
12687
0
SLANG_RAW("}\n")
12688
0
SLANG_RAW("\n")
12689
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12690
0
SLANG_RAW("[__readNone]\n")
12691
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12692
0
SLANG_RAW("vector<T, N> log(vector<T, N> x)\n")
12693
0
SLANG_RAW("{\n")
12694
0
SLANG_RAW("    __target_switch\n")
12695
0
SLANG_RAW("    {\n")
12696
0
SLANG_RAW("    case glsl: __intrinsic_asm \"log\";\n")
12697
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log\";\n")
12698
0
SLANG_RAW("    case metal: __intrinsic_asm \"log\";\n")
12699
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12700
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Log $x\n")
12701
0
SLANG_RAW("    };\n")
12702
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"log\";\n")
12703
0
SLANG_RAW("    default:\n")
12704
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, log, x);\n")
12705
0
SLANG_RAW("    }\n")
12706
0
SLANG_RAW("}\n")
12707
0
SLANG_RAW("\n")
12708
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12709
0
SLANG_RAW("[__readNone]\n")
12710
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12711
0
SLANG_RAW("matrix<T, N, M> log(matrix<T, N, M> x)\n")
12712
0
SLANG_RAW("{\n")
12713
0
SLANG_RAW("    __target_switch\n")
12714
0
SLANG_RAW("    {\n")
12715
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log\";\n")
12716
0
SLANG_RAW("    default:\n")
12717
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, log, x);\n")
12718
0
SLANG_RAW("    }\n")
12719
0
SLANG_RAW("}\n")
12720
0
SLANG_RAW("\n")
12721
0
SLANG_RAW("/// Compute base-10 logarithm.\n")
12722
0
SLANG_RAW("/// @param x The input value.\n")
12723
0
SLANG_RAW("/// @return The base-10 logarithm of `x`.\n")
12724
0
SLANG_RAW("/// @category math\n")
12725
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12726
0
SLANG_RAW("[__readNone]\n")
12727
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12728
0
SLANG_RAW("T log10(T x)\n")
12729
0
SLANG_RAW("{\n")
12730
0
SLANG_RAW("    __target_switch\n")
12731
0
SLANG_RAW("    {\n")
12732
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log10\";\n")
12733
0
SLANG_RAW("    case metal: __intrinsic_asm \"log10\";\n")
12734
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"(log( $0 ) * $S0( 0.43429448190325182765112891891661) )\";\n")
12735
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(log( $0 ) * $S0( 0.43429448190325182765112891891661) )\";\n")
12736
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_log10($0)\";\n")
12737
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_log10($0)\";\n")
12738
0
SLANG_RAW("    case spirv:\n")
12739
0
SLANG_RAW("    {\n")
12740
0
SLANG_RAW("        const T tmp = T(0.43429448190325182765112891891661);\n")
12741
0
SLANG_RAW("        return spirv_asm {\n")
12742
0
SLANG_RAW("            %baseElog:$$T = OpExtInst glsl450 Log $x;\n")
12743
0
SLANG_RAW("            result:$$T = OpFMul %baseElog $tmp\n")
12744
0
SLANG_RAW("        };\n")
12745
0
SLANG_RAW("    }\n")
12746
0
SLANG_RAW("    }\n")
12747
0
SLANG_RAW("}\n")
12748
0
SLANG_RAW("\n")
12749
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12750
0
SLANG_RAW("[__readNone]\n")
12751
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12752
0
SLANG_RAW("vector<T,N> log10(vector<T,N> x)\n")
12753
0
SLANG_RAW("{\n")
12754
0
SLANG_RAW("    __target_switch\n")
12755
0
SLANG_RAW("    {\n")
12756
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log10\";\n")
12757
0
SLANG_RAW("    case metal: __intrinsic_asm \"log10\";\n")
12758
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\";\n")
12759
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\";\n")
12760
0
SLANG_RAW("    case spirv:\n")
12761
0
SLANG_RAW("    {\n")
12762
0
SLANG_RAW("        const T tmp = T(0.43429448190325182765112891891661);\n")
12763
0
SLANG_RAW("        return spirv_asm {\n")
12764
0
SLANG_RAW("            %baseElog:$$vector<T,N> = OpExtInst glsl450 Log $x;\n")
12765
0
SLANG_RAW("            result:$$vector<T,N> = OpVectorTimesScalar %baseElog $tmp\n")
12766
0
SLANG_RAW("        };\n")
12767
0
SLANG_RAW("    }\n")
12768
0
SLANG_RAW("    default:\n")
12769
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, log10, x);\n")
12770
0
SLANG_RAW("    }\n")
12771
0
SLANG_RAW("}\n")
12772
0
SLANG_RAW("\n")
12773
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12774
0
SLANG_RAW("[__readNone]\n")
12775
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
12776
0
SLANG_RAW("matrix<T,N,M> log10(matrix<T,N,M> x)\n")
12777
0
SLANG_RAW("{\n")
12778
0
SLANG_RAW("    __target_switch\n")
12779
0
SLANG_RAW("    {\n")
12780
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log10\";\n")
12781
0
SLANG_RAW("    default:\n")
12782
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, log10, x);\n")
12783
0
SLANG_RAW("    }\n")
12784
0
SLANG_RAW("}\n")
12785
0
SLANG_RAW("\n")
12786
0
SLANG_RAW("/// Compute base-2 logarithm.\n")
12787
0
SLANG_RAW("/// @param x The input value.\n")
12788
0
SLANG_RAW("/// @return The base-2 logarithm of `x`.\n")
12789
0
SLANG_RAW("/// @category math\n")
12790
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12791
0
SLANG_RAW("[__readNone]\n")
12792
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12793
0
SLANG_RAW("T log2(T x)\n")
12794
0
SLANG_RAW("{\n")
12795
0
SLANG_RAW("    __target_switch\n")
12796
0
SLANG_RAW("    {\n")
12797
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_log2($0)\";\n")
12798
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_log2($0)\";\n")
12799
0
SLANG_RAW("    case glsl: __intrinsic_asm \"log2\";\n")
12800
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log2\";\n")
12801
0
SLANG_RAW("    case metal: __intrinsic_asm \"log2\";\n")
12802
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12803
0
SLANG_RAW("        OpExtInst $$T result glsl450 Log2 $x\n")
12804
0
SLANG_RAW("    };\n")
12805
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"log2\";\n")
12806
0
SLANG_RAW("    }\n")
12807
0
SLANG_RAW("}\n")
12808
0
SLANG_RAW("\n")
12809
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12810
0
SLANG_RAW("[__readNone]\n")
12811
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12812
0
SLANG_RAW("vector<T,N> log2(vector<T,N> x)\n")
12813
0
SLANG_RAW("{\n")
12814
0
SLANG_RAW("    __target_switch\n")
12815
0
SLANG_RAW("    {\n")
12816
0
SLANG_RAW("    case glsl: __intrinsic_asm \"log2\";\n")
12817
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log2\";\n")
12818
0
SLANG_RAW("    case metal: __intrinsic_asm \"log2\";\n")
12819
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12820
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Log2 $x\n")
12821
0
SLANG_RAW("    };\n")
12822
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"log2\";\n")
12823
0
SLANG_RAW("    default:\n")
12824
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, log2, x);\n")
12825
0
SLANG_RAW("    }\n")
12826
0
SLANG_RAW("}\n")
12827
0
SLANG_RAW("\n")
12828
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12829
0
SLANG_RAW("[__readNone]\n")
12830
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12831
0
SLANG_RAW("matrix<T,N,M> log2(matrix<T,N,M> x)\n")
12832
0
SLANG_RAW("{\n")
12833
0
SLANG_RAW("    __target_switch\n")
12834
0
SLANG_RAW("    {\n")
12835
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"log2\";\n")
12836
0
SLANG_RAW("    default:\n")
12837
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, log2, x);\n")
12838
0
SLANG_RAW("    }\n")
12839
0
SLANG_RAW("}\n")
12840
0
SLANG_RAW("\n")
12841
0
SLANG_RAW("/// Computes multiply-add.\n")
12842
0
SLANG_RAW("/// @param mvalue The multiplier.\n")
12843
0
SLANG_RAW("/// @param avalue The multiplicand.\n")
12844
0
SLANG_RAW("/// @param bvalue The addend.\n")
12845
0
SLANG_RAW("/// @return The result of `mvalue * avalue + bvalue`.\n")
12846
0
SLANG_RAW("/// @category math\n")
12847
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
12848
0
SLANG_RAW("[__readNone]\n")
12849
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
12850
0
SLANG_RAW("T mad(T mvalue, T avalue, T bvalue)\n")
12851
0
SLANG_RAW("{\n")
12852
0
SLANG_RAW("    __target_switch\n")
12853
0
SLANG_RAW("    {\n")
12854
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
12855
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
12856
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
12857
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12858
0
SLANG_RAW("    case metal: __intrinsic_asm \"fma\";\n")
12859
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12860
0
SLANG_RAW("        OpExtInst $$T result glsl450 Fma $mvalue $avalue $bvalue\n")
12861
0
SLANG_RAW("    };\n")
12862
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fma\";\n")
12863
0
SLANG_RAW("    }\n")
12864
0
SLANG_RAW("}\n")
12865
0
SLANG_RAW("\n")
12866
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
12867
0
SLANG_RAW("[__readNone]\n")
12868
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
12869
0
SLANG_RAW("vector<T, N> mad(vector<T, N> mvalue, vector<T, N> avalue, vector<T, N> bvalue)\n")
12870
0
SLANG_RAW("{\n")
12871
0
SLANG_RAW("    __target_switch\n")
12872
0
SLANG_RAW("    {\n")
12873
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
12874
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12875
0
SLANG_RAW("    case metal: __intrinsic_asm \"fma\";\n")
12876
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12877
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Fma $mvalue $avalue $bvalue\n")
12878
0
SLANG_RAW("    };\n")
12879
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"fma\";\n")
12880
0
SLANG_RAW("    default:\n")
12881
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, mad, mvalue, avalue, bvalue);\n")
12882
0
SLANG_RAW("    }\n")
12883
0
SLANG_RAW("}\n")
12884
0
SLANG_RAW("\n")
12885
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
12886
0
SLANG_RAW("[__readNone]\n")
12887
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_5_0)]\n")
12888
0
SLANG_RAW("matrix<T, N, M> mad(matrix<T, N, M> mvalue, matrix<T, N, M> avalue, matrix<T, N, M> bvalue)\n")
12889
0
SLANG_RAW("{\n")
12890
0
SLANG_RAW("    __target_switch\n")
12891
0
SLANG_RAW("    {\n")
12892
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12893
0
SLANG_RAW("    default:\n")
12894
0
SLANG_RAW("        MATRIX_MAP_TRINARY(T, N, M, mad, mvalue, avalue, bvalue);\n")
12895
0
SLANG_RAW("    }\n")
12896
0
SLANG_RAW("}\n")
12897
0
SLANG_RAW("\n")
12898
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
12899
0
SLANG_RAW("[__readNone]\n")
12900
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
12901
0
SLANG_RAW("T mad(T mvalue, T avalue, T bvalue)\n")
12902
0
SLANG_RAW("{\n")
12903
0
SLANG_RAW("    __target_switch\n")
12904
0
SLANG_RAW("    {\n")
12905
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
12906
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_fma($0, $1, $2)\";\n")
12907
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
12908
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12909
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12910
0
SLANG_RAW("        OpExtInst $$T result glsl450 Fma $mvalue $avalue $bvalue\n")
12911
0
SLANG_RAW("    };\n")
12912
0
SLANG_RAW("    }\n")
12913
0
SLANG_RAW("}\n")
12914
0
SLANG_RAW("\n")
12915
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
12916
0
SLANG_RAW("[__readNone]\n")
12917
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
12918
0
SLANG_RAW("vector<T, N> mad(vector<T, N> mvalue, vector<T, N> avalue, vector<T, N> bvalue)\n")
12919
0
SLANG_RAW("{\n")
12920
0
SLANG_RAW("    __target_switch\n")
12921
0
SLANG_RAW("    {\n")
12922
0
SLANG_RAW("    case glsl: __intrinsic_asm \"fma\";\n")
12923
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12924
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
12925
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Fma $mvalue $avalue $bvalue\n")
12926
0
SLANG_RAW("    };\n")
12927
0
SLANG_RAW("    default:\n")
12928
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, mad, mvalue, avalue, bvalue);\n")
12929
0
SLANG_RAW("    }\n")
12930
0
SLANG_RAW("}\n")
12931
0
SLANG_RAW("\n")
12932
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
12933
0
SLANG_RAW("[__readNone]\n")
12934
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shader5_sm_5_0)]\n")
12935
0
SLANG_RAW("matrix<T, N, M> mad(matrix<T, N, M> mvalue, matrix<T, N, M> avalue, matrix<T, N, M> bvalue)\n")
12936
0
SLANG_RAW("{\n")
12937
0
SLANG_RAW("    __target_switch\n")
12938
0
SLANG_RAW("    {\n")
12939
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mad\";\n")
12940
0
SLANG_RAW("    default:\n")
12941
0
SLANG_RAW("        MATRIX_MAP_TRINARY(T, N, M, mad, mvalue, avalue, bvalue);\n")
12942
0
SLANG_RAW("    }\n")
12943
0
SLANG_RAW("}\n")
12944
0
SLANG_RAW("\n")
12945
0
SLANG_RAW("/// Maximum.\n")
12946
0
SLANG_RAW("/// @param x The first value.\n")
12947
0
SLANG_RAW("/// @param y The second value.\n")
12948
0
SLANG_RAW("/// @return The maximum of `x` and `y`.\n")
12949
0
SLANG_RAW("/// @category math\n")
12950
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
12951
0
SLANG_RAW("[__readNone]\n")
12952
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12953
0
SLANG_RAW("T max(T x, T y)\n")
12954
0
SLANG_RAW("{\n")
12955
0
SLANG_RAW("    // Note: a core module implementation of `max` (or `min`) will require splitting\n")
12956
0
SLANG_RAW("    // floating-point and integer cases apart, because the floating-point\n")
12957
0
SLANG_RAW("    // version needs to correctly handle the case where one of the inputs\n")
12958
0
SLANG_RAW("    // is not-a-number.\n")
12959
0
SLANG_RAW("\n")
12960
0
SLANG_RAW("    __target_switch\n")
12961
0
SLANG_RAW("    {\n")
12962
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
12963
0
SLANG_RAW("    case glsl: __intrinsic_asm \"max\";\n")
12964
0
SLANG_RAW("    case metal: __intrinsic_asm \"max\";\n")
12965
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_max($0, $1)\";\n")
12966
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_max($0, $1)\";\n")
12967
0
SLANG_RAW("    case spirv:\n")
12968
0
SLANG_RAW("    {\n")
12969
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
12970
0
SLANG_RAW("        {\n")
12971
0
SLANG_RAW("            return spirv_asm {\n")
12972
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 SMax $x $y\n")
12973
0
SLANG_RAW("            };\n")
12974
0
SLANG_RAW("        }\n")
12975
0
SLANG_RAW("        else\n")
12976
0
SLANG_RAW("        {\n")
12977
0
SLANG_RAW("            return spirv_asm {\n")
12978
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 UMax $x $y\n")
12979
0
SLANG_RAW("            };\n")
12980
0
SLANG_RAW("        }\n")
12981
0
SLANG_RAW("    }\n")
12982
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"max\";\n")
12983
0
SLANG_RAW("    }\n")
12984
0
SLANG_RAW("}\n")
12985
0
SLANG_RAW("\n")
12986
0
SLANG_RAW("/// @category math\n")
12987
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
12988
0
SLANG_RAW("[__readNone]\n")
12989
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
12990
0
SLANG_RAW("vector<T, N> max(vector<T, N> x, vector<T, N> y)\n")
12991
0
SLANG_RAW("{\n")
12992
0
SLANG_RAW("    __target_switch\n")
12993
0
SLANG_RAW("    {\n")
12994
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
12995
0
SLANG_RAW("    case glsl: __intrinsic_asm \"max\";\n")
12996
0
SLANG_RAW("    case metal: __intrinsic_asm \"max\";\n")
12997
0
SLANG_RAW("    case spirv:\n")
12998
0
SLANG_RAW("    {\n")
12999
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
13000
0
SLANG_RAW("        {\n")
13001
0
SLANG_RAW("            return spirv_asm {\n")
13002
0
SLANG_RAW("                result:$$vector<T,N> = OpExtInst glsl450 SMax $x $y\n")
13003
0
SLANG_RAW("            };\n")
13004
0
SLANG_RAW("        }\n")
13005
0
SLANG_RAW("        else\n")
13006
0
SLANG_RAW("        {\n")
13007
0
SLANG_RAW("            return spirv_asm {\n")
13008
0
SLANG_RAW("                result:$$vector<T,N> = OpExtInst glsl450 UMax $x $y\n")
13009
0
SLANG_RAW("            };\n")
13010
0
SLANG_RAW("        }\n")
13011
0
SLANG_RAW("    }\n")
13012
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"max\";\n")
13013
0
SLANG_RAW("    default:\n")
13014
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, max, x, y);\n")
13015
0
SLANG_RAW("    }\n")
13016
0
SLANG_RAW("}\n")
13017
0
SLANG_RAW("\n")
13018
0
SLANG_RAW("/// @category math\n")
13019
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
13020
0
SLANG_RAW("[__readNone]\n")
13021
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13022
0
SLANG_RAW("matrix<T, N, M> max(matrix<T, N, M> x, matrix<T, N, M> y)\n")
13023
0
SLANG_RAW("{\n")
13024
0
SLANG_RAW("    __target_switch\n")
13025
0
SLANG_RAW("    {\n")
13026
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
13027
0
SLANG_RAW("    default:\n")
13028
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, max, x, y);\n")
13029
0
SLANG_RAW("    }\n")
13030
0
SLANG_RAW("}\n")
13031
0
SLANG_RAW("\n")
13032
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13033
0
SLANG_RAW("[__readNone]\n")
13034
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13035
0
SLANG_RAW("T max(T x, T y)\n")
13036
0
SLANG_RAW("{\n")
13037
0
SLANG_RAW("    __target_switch\n")
13038
0
SLANG_RAW("    {\n")
13039
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
13040
0
SLANG_RAW("    case metal: __intrinsic_asm \"max\";\n")
13041
0
SLANG_RAW("    case glsl: __intrinsic_asm \"max\";\n")
13042
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_max($0, $1)\";\n")
13043
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_max($0, $1)\";\n")
13044
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13045
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 FMax $x $y\n")
13046
0
SLANG_RAW("    };\n")
13047
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"max\";\n")
13048
0
SLANG_RAW("    }\n")
13049
0
SLANG_RAW("}\n")
13050
0
SLANG_RAW("\n")
13051
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13052
0
SLANG_RAW("[__readNone]\n")
13053
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13054
0
SLANG_RAW("vector<T, N> max(vector<T, N> x, vector<T, N> y)\n")
13055
0
SLANG_RAW("{\n")
13056
0
SLANG_RAW("    __target_switch\n")
13057
0
SLANG_RAW("    {\n")
13058
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
13059
0
SLANG_RAW("    case metal: __intrinsic_asm \"max\";\n")
13060
0
SLANG_RAW("    case glsl: __intrinsic_asm \"max\";\n")
13061
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13062
0
SLANG_RAW("        result:$$vector<T, N> = OpExtInst glsl450 FMax $x $y\n")
13063
0
SLANG_RAW("    };\n")
13064
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"max\";\n")
13065
0
SLANG_RAW("    default:\n")
13066
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, max, x, y);\n")
13067
0
SLANG_RAW("    }\n")
13068
0
SLANG_RAW("}\n")
13069
0
SLANG_RAW("\n")
13070
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
13071
0
SLANG_RAW("[__readNone]\n")
13072
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13073
0
SLANG_RAW("matrix<T, N, M> max(matrix<T, N, M> x, matrix<T, N, M> y)\n")
13074
0
SLANG_RAW("{\n")
13075
0
SLANG_RAW("    __target_switch\n")
13076
0
SLANG_RAW("    {\n")
13077
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"max\";\n")
13078
0
SLANG_RAW("    default:\n")
13079
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, max, x, y);\n")
13080
0
SLANG_RAW("    }\n")
13081
0
SLANG_RAW("}\n")
13082
0
SLANG_RAW("\n")
13083
0
SLANG_RAW("/// Maximum of 3 inputs.\n")
13084
0
SLANG_RAW("/// @param x The first value to compare.\n")
13085
0
SLANG_RAW("/// @param y The second value to compare.\n")
13086
0
SLANG_RAW("/// @param z The third value to compare.\n")
13087
0
SLANG_RAW("/// @return The largest of the three values, element-wise if vector typed.\n")
13088
0
SLANG_RAW("/// @category math\n")
13089
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13090
0
SLANG_RAW("[__readNone]\n")
13091
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13092
0
SLANG_RAW("T max3(T x, T y, T z)\n")
13093
0
SLANG_RAW("{\n")
13094
0
SLANG_RAW("    __target_switch\n")
13095
0
SLANG_RAW("    {\n")
13096
0
SLANG_RAW("    case metal: __intrinsic_asm \"max3\";\n")
13097
0
SLANG_RAW("    default:\n")
13098
0
SLANG_RAW("        return max(x, max(y, z));\n")
13099
0
SLANG_RAW("    }\n")
13100
0
SLANG_RAW("}\n")
13101
0
SLANG_RAW("\n")
13102
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
13103
0
SLANG_RAW("[__readNone]\n")
13104
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13105
0
SLANG_RAW("vector<T,N> max3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13106
0
SLANG_RAW("{\n")
13107
0
SLANG_RAW("    __target_switch\n")
13108
0
SLANG_RAW("    {\n")
13109
0
SLANG_RAW("    case metal: __intrinsic_asm \"max3\";\n")
13110
0
SLANG_RAW("    default:\n")
13111
0
SLANG_RAW("        return max(x, max(y, z));\n")
13112
0
SLANG_RAW("    }\n")
13113
0
SLANG_RAW("}\n")
13114
0
SLANG_RAW("\n")
13115
0
SLANG_RAW("/// Floating-point maximum.\n")
13116
0
SLANG_RAW("/// @param x The first value to compare.\n")
13117
0
SLANG_RAW("/// @param y The second value to compare.\n")
13118
0
SLANG_RAW("/// @return The larger of the two values, element-wise if vector typed.\n")
13119
0
SLANG_RAW("/// @remarks Result is `y` if `x` < `y`, either `x` or `y` if both `x` and `y` are zeros, otherwise `x`. Which operand is the result is undefined if one of the operands is a NaN.\n")
13120
0
SLANG_RAW("/// @category math\n")
13121
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13122
0
SLANG_RAW("[__readNone]\n")
13123
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13124
0
SLANG_RAW("T fmax(T x, T y)\n")
13125
0
SLANG_RAW("{\n")
13126
0
SLANG_RAW("    __target_switch\n")
13127
0
SLANG_RAW("    {\n")
13128
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmax\";\n")
13129
0
SLANG_RAW("    default:\n")
13130
0
SLANG_RAW("        return max(x, y);\n")
13131
0
SLANG_RAW("    }\n")
13132
0
SLANG_RAW("}\n")
13133
0
SLANG_RAW("\n")
13134
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
13135
0
SLANG_RAW("[__readNone]\n")
13136
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13137
0
SLANG_RAW("vector<T,N> fmax(vector<T,N> x, vector<T,N> y)\n")
13138
0
SLANG_RAW("{\n")
13139
0
SLANG_RAW("    __target_switch\n")
13140
0
SLANG_RAW("    {\n")
13141
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmax\";\n")
13142
0
SLANG_RAW("    default:\n")
13143
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, fmax, x, y);\n")
13144
0
SLANG_RAW("    }\n")
13145
0
SLANG_RAW("}\n")
13146
0
SLANG_RAW("\n")
13147
0
SLANG_RAW("/// Floating-point maximum of 3 inputs.\n")
13148
0
SLANG_RAW("/// @param x The first value to compare.\n")
13149
0
SLANG_RAW("/// @param y The second value to compare.\n")
13150
0
SLANG_RAW("/// @param z The third value to compare.\n")
13151
0
SLANG_RAW("/// @return The largest of the three values, element-wise if vector typed.\n")
13152
0
SLANG_RAW("/// @remarks If any operand in the 3-way comparison is NaN, it is undefined which operand is returned.\n")
13153
0
SLANG_RAW("/// @category math\n")
13154
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13155
0
SLANG_RAW("[__readNone]\n")
13156
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13157
0
SLANG_RAW("T fmax3(T x, T y, T z)\n")
13158
0
SLANG_RAW("{\n")
13159
0
SLANG_RAW("    __target_switch\n")
13160
0
SLANG_RAW("    {\n")
13161
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmax3\";\n")
13162
0
SLANG_RAW("    default:\n")
13163
0
SLANG_RAW("    {\n")
13164
0
SLANG_RAW("        return max(y, max(x, z));\n")
13165
0
SLANG_RAW("    }\n")
13166
0
SLANG_RAW("    }\n")
13167
0
SLANG_RAW("}\n")
13168
0
SLANG_RAW("\n")
13169
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
13170
0
SLANG_RAW("[__readNone]\n")
13171
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13172
0
SLANG_RAW("vector<T,N> fmax3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13173
0
SLANG_RAW("{\n")
13174
0
SLANG_RAW("    __target_switch\n")
13175
0
SLANG_RAW("    {\n")
13176
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmax3\";\n")
13177
0
SLANG_RAW("    default:\n")
13178
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, fmax3, x, y, z);\n")
13179
0
SLANG_RAW("    }\n")
13180
0
SLANG_RAW("}\n")
13181
0
SLANG_RAW("\n")
13182
0
SLANG_RAW("/// Minimum.\n")
13183
0
SLANG_RAW("/// @param x The first value to compare.\n")
13184
0
SLANG_RAW("/// @param y The second value to compare.\n")
13185
0
SLANG_RAW("/// @return The smaller of the two values, element-wise if vector typed.\n")
13186
0
SLANG_RAW("/// @remarks For HLSL, GLSL, and metal targets, this is implemented with the min() intrinsic.\n")
13187
0
SLANG_RAW("/// For SPIR-V, it is implemented with the UMin or SMin instruction, depending on the signedness of the type.\n")
13188
0
SLANG_RAW("/// @category math\n")
13189
0
SLANG_RAW("__generic<T : __BuiltinIntegerType>\n")
13190
0
SLANG_RAW("[__readNone]\n")
13191
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13192
0
SLANG_RAW("T min(T x, T y)\n")
13193
0
SLANG_RAW("{\n")
13194
0
SLANG_RAW("    __target_switch\n")
13195
0
SLANG_RAW("    {\n")
13196
0
SLANG_RAW("    case hlsl:\n")
13197
0
SLANG_RAW("    case glsl:\n")
13198
0
SLANG_RAW("    case metal:\n")
13199
0
SLANG_RAW("        __intrinsic_asm \"min\";\n")
13200
0
SLANG_RAW("    case cuda:\n")
13201
0
SLANG_RAW("    case cpp:\n")
13202
0
SLANG_RAW("        __intrinsic_asm \"$P_min($0, $1)\";\n")
13203
0
SLANG_RAW("    case spirv:\n")
13204
0
SLANG_RAW("    {\n")
13205
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
13206
0
SLANG_RAW("            return spirv_asm {\n")
13207
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 SMin $x $y\n")
13208
0
SLANG_RAW("            };\n")
13209
0
SLANG_RAW("        else\n")
13210
0
SLANG_RAW("            return spirv_asm {\n")
13211
0
SLANG_RAW("                result:$$T = OpExtInst glsl450 UMin $x $y\n")
13212
0
SLANG_RAW("            };\n")
13213
0
SLANG_RAW("    }\n")
13214
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"min\";\n")
13215
0
SLANG_RAW("    }\n")
13216
0
SLANG_RAW("}\n")
13217
0
SLANG_RAW("\n")
13218
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
13219
0
SLANG_RAW("[__readNone]\n")
13220
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13221
0
SLANG_RAW("vector<T,N> min(vector<T,N> x, vector<T,N> y)\n")
13222
0
SLANG_RAW("{\n")
13223
0
SLANG_RAW("    __target_switch\n")
13224
0
SLANG_RAW("    {\n")
13225
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"min\";\n")
13226
0
SLANG_RAW("    case glsl: __intrinsic_asm \"min\";\n")
13227
0
SLANG_RAW("    case metal: __intrinsic_asm \"min\";\n")
13228
0
SLANG_RAW("    case spirv:\n")
13229
0
SLANG_RAW("    {\n")
13230
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
13231
0
SLANG_RAW("            return spirv_asm {\n")
13232
0
SLANG_RAW("                result:$$vector<T,N> = OpExtInst glsl450 SMin $x $y\n")
13233
0
SLANG_RAW("            };\n")
13234
0
SLANG_RAW("        else\n")
13235
0
SLANG_RAW("            return spirv_asm {\n")
13236
0
SLANG_RAW("                result:$$vector<T,N> = OpExtInst glsl450 UMin $x $y\n")
13237
0
SLANG_RAW("            };\n")
13238
0
SLANG_RAW("    }\n")
13239
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"min\";\n")
13240
0
SLANG_RAW("    default:\n")
13241
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, min, x, y);\n")
13242
0
SLANG_RAW("    }\n")
13243
0
SLANG_RAW("}\n")
13244
0
SLANG_RAW("\n")
13245
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
13246
0
SLANG_RAW("[__readNone]\n")
13247
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13248
0
SLANG_RAW("matrix<T,N,M> min(matrix<T,N,M> x, matrix<T,N,M> y)\n")
13249
0
SLANG_RAW("{\n")
13250
0
SLANG_RAW("    __target_switch\n")
13251
0
SLANG_RAW("    {\n")
13252
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"min\";\n")
13253
0
SLANG_RAW("    default:\n")
13254
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, min, x, y);\n")
13255
0
SLANG_RAW("    }\n")
13256
0
SLANG_RAW("}\n")
13257
0
SLANG_RAW("\n")
13258
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13259
0
SLANG_RAW("[__readNone]\n")
13260
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13261
0
SLANG_RAW("T min(T x, T y)\n")
13262
0
SLANG_RAW("{\n")
13263
0
SLANG_RAW("    __target_switch\n")
13264
0
SLANG_RAW("    {\n")
13265
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"min\";\n")
13266
0
SLANG_RAW("    case metal: __intrinsic_asm \"min\";\n")
13267
0
SLANG_RAW("    case glsl: __intrinsic_asm \"min\";\n")
13268
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_min($0, $1)\";\n")
13269
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_min($0, $1)\";\n")
13270
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13271
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 FMin $x $y\n")
13272
0
SLANG_RAW("    };\n")
13273
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"min\";\n")
13274
0
SLANG_RAW("    }\n")
13275
0
SLANG_RAW("}\n")
13276
0
SLANG_RAW("\n")
13277
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13278
0
SLANG_RAW("[__readNone]\n")
13279
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13280
0
SLANG_RAW("vector<T,N> min(vector<T,N> x, vector<T,N> y)\n")
13281
0
SLANG_RAW("{\n")
13282
0
SLANG_RAW("    __target_switch\n")
13283
0
SLANG_RAW("    {\n")
13284
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"min\";\n")
13285
0
SLANG_RAW("    case metal: __intrinsic_asm \"min\";\n")
13286
0
SLANG_RAW("    case glsl: __intrinsic_asm \"min\";\n")
13287
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13288
0
SLANG_RAW("        result:$$vector<T,N> = OpExtInst glsl450 FMin $x $y\n")
13289
0
SLANG_RAW("    };\n")
13290
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"min\";\n")
13291
0
SLANG_RAW("    default:\n")
13292
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, min, x, y);\n")
13293
0
SLANG_RAW("    }\n")
13294
0
SLANG_RAW("}\n")
13295
0
SLANG_RAW("\n")
13296
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
13297
0
SLANG_RAW("[__readNone]\n")
13298
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13299
0
SLANG_RAW("matrix<T,N,M> min(matrix<T,N,M> x, matrix<T,N,M> y)\n")
13300
0
SLANG_RAW("{\n")
13301
0
SLANG_RAW("    __target_switch\n")
13302
0
SLANG_RAW("    {\n")
13303
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"min\";\n")
13304
0
SLANG_RAW("    default:\n")
13305
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, min, x, y);\n")
13306
0
SLANG_RAW("    }\n")
13307
0
SLANG_RAW("}\n")
13308
0
SLANG_RAW("\n")
13309
0
SLANG_RAW("/// Minimum of 3 inputs.\n")
13310
0
SLANG_RAW("/// @param x The first value to compare.\n")
13311
0
SLANG_RAW("/// @param y The second value to compare.\n")
13312
0
SLANG_RAW("/// @param z The third value to compare.\n")
13313
0
SLANG_RAW("/// @return The smallest of the three values, element-wise if vector typed.\n")
13314
0
SLANG_RAW("/// @category math\n")
13315
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13316
0
SLANG_RAW("[__readNone]\n")
13317
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13318
0
SLANG_RAW("T min3(T x, T y, T z)\n")
13319
0
SLANG_RAW("{\n")
13320
0
SLANG_RAW("    __target_switch\n")
13321
0
SLANG_RAW("    {\n")
13322
0
SLANG_RAW("    case metal: __intrinsic_asm \"min3\";\n")
13323
0
SLANG_RAW("    default:\n")
13324
0
SLANG_RAW("        return min(x, min(y, z));\n")
13325
0
SLANG_RAW("    }\n")
13326
0
SLANG_RAW("}\n")
13327
0
SLANG_RAW("\n")
13328
0
SLANG_RAW("/// @category math\n")
13329
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13330
0
SLANG_RAW("[__readNone]\n")
13331
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13332
0
SLANG_RAW("vector<T,N> min3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13333
0
SLANG_RAW("{\n")
13334
0
SLANG_RAW("    __target_switch\n")
13335
0
SLANG_RAW("    {\n")
13336
0
SLANG_RAW("    case metal: __intrinsic_asm \"min3\";\n")
13337
0
SLANG_RAW("    default:\n")
13338
0
SLANG_RAW("        return min(x, min(y, z));\n")
13339
0
SLANG_RAW("    }\n")
13340
0
SLANG_RAW("}\n")
13341
0
SLANG_RAW("\n")
13342
0
SLANG_RAW("/// Floating-point minimum.\n")
13343
0
SLANG_RAW("/// @param x The first value to compare.\n")
13344
0
SLANG_RAW("/// @param y The second value to compare.\n")
13345
0
SLANG_RAW("/// @return The smaller of the two values, element-wise if vector typed.\n")
13346
0
SLANG_RAW("/// @remarks Result is `x` if `x` < `y`, either `x` or `y` if both `x` and `y` are zeros, otherwise `y`. Which operand is the result is undefined if one of the operands is a NaN.\n")
13347
0
SLANG_RAW("/// @category math\n")
13348
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13349
0
SLANG_RAW("[__readNone]\n")
13350
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13351
0
SLANG_RAW("T fmin(T x, T y)\n")
13352
0
SLANG_RAW("{\n")
13353
0
SLANG_RAW("    __target_switch\n")
13354
0
SLANG_RAW("    {\n")
13355
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmin\";\n")
13356
0
SLANG_RAW("    default:\n")
13357
0
SLANG_RAW("        return min(x, y);\n")
13358
0
SLANG_RAW("    }\n")
13359
0
SLANG_RAW("}\n")
13360
0
SLANG_RAW("\n")
13361
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13362
0
SLANG_RAW("[__readNone]\n")
13363
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13364
0
SLANG_RAW("vector<T,N> fmin(vector<T,N> x, vector<T,N> y)\n")
13365
0
SLANG_RAW("{\n")
13366
0
SLANG_RAW("    __target_switch\n")
13367
0
SLANG_RAW("    {\n")
13368
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmin\";\n")
13369
0
SLANG_RAW("    default:\n")
13370
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, fmin, x, y);\n")
13371
0
SLANG_RAW("    }\n")
13372
0
SLANG_RAW("}\n")
13373
0
SLANG_RAW("\n")
13374
0
SLANG_RAW("/// Floating-point minimum of 3 inputs.\n")
13375
0
SLANG_RAW("/// @param x The first value to compare.\n")
13376
0
SLANG_RAW("/// @param y The second value to compare.\n")
13377
0
SLANG_RAW("/// @param z The third value to compare.\n")
13378
0
SLANG_RAW("/// @return The smallest of the three values, element-wise if vector typed.\n")
13379
0
SLANG_RAW("/// @remarks If any operand in the 3-way comparison is NaN, it is undefined which operand is returned.\n")
13380
0
SLANG_RAW("/// @category math\n")
13381
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13382
0
SLANG_RAW("[__readNone]\n")
13383
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13384
0
SLANG_RAW("T fmin3(T x, T y, T z)\n")
13385
0
SLANG_RAW("{\n")
13386
0
SLANG_RAW("    __target_switch\n")
13387
0
SLANG_RAW("    {\n")
13388
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmin3\";\n")
13389
0
SLANG_RAW("    default:\n")
13390
0
SLANG_RAW("    {\n")
13391
0
SLANG_RAW("        return min(x, min(y, z));\n")
13392
0
SLANG_RAW("    }\n")
13393
0
SLANG_RAW("    }\n")
13394
0
SLANG_RAW("}\n")
13395
0
SLANG_RAW("\n")
13396
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13397
0
SLANG_RAW("[__readNone]\n")
13398
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13399
0
SLANG_RAW("vector<T,N> fmin3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13400
0
SLANG_RAW("{\n")
13401
0
SLANG_RAW("    __target_switch\n")
13402
0
SLANG_RAW("    {\n")
13403
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmin3\";\n")
13404
0
SLANG_RAW("    default:\n")
13405
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, fmin3, x, y, z);\n")
13406
0
SLANG_RAW("    }\n")
13407
0
SLANG_RAW("}\n")
13408
0
SLANG_RAW("\n")
13409
0
SLANG_RAW("/// Median of 3 values.\n")
13410
0
SLANG_RAW("/// @param x The first value to compare.\n")
13411
0
SLANG_RAW("/// @param y The second value to compare.\n")
13412
0
SLANG_RAW("/// @param z The third value to compare.\n")
13413
0
SLANG_RAW("/// @return The median of the three values, element-wise if vector typed.\n")
13414
0
SLANG_RAW("/// @remarks For metal, this is implemented with the median3 intrinsic which has special handling for NaN.\n")
13415
0
SLANG_RAW("/// @category math\n")
13416
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13417
0
SLANG_RAW("[__readNone]\n")
13418
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13419
0
SLANG_RAW("T median3(T x, T y, T z)\n")
13420
0
SLANG_RAW("{\n")
13421
0
SLANG_RAW("    __target_switch\n")
13422
0
SLANG_RAW("    {\n")
13423
0
SLANG_RAW("    case metal: __intrinsic_asm \"median3\";\n")
13424
0
SLANG_RAW("    default:\n")
13425
0
SLANG_RAW("    {\n")
13426
0
SLANG_RAW("        //           | a | b | c | m |\n")
13427
0
SLANG_RAW("        // ----------+---+---+---+---+\n")
13428
0
SLANG_RAW("        // x > y > z | z | y | x | y |\n")
13429
0
SLANG_RAW("        // x > z > y | y | z | x | z |\n")
13430
0
SLANG_RAW("        // y > x > z | z | y | x | x |\n")
13431
0
SLANG_RAW("        // y > z > x | z | y | z | z |\n")
13432
0
SLANG_RAW("        // z > x > y | y | z | x | x |\n")
13433
0
SLANG_RAW("        // z > y > x | y | z | y | y |\n")
13434
0
SLANG_RAW("\n")
13435
0
SLANG_RAW("        T a = min(y, z);\n")
13436
0
SLANG_RAW("        T b = max(y, z);\n")
13437
0
SLANG_RAW("        T c = max(x, a);\n")
13438
0
SLANG_RAW("        T m = min(b, c);\n")
13439
0
SLANG_RAW("        return m;\n")
13440
0
SLANG_RAW("    }\n")
13441
0
SLANG_RAW("    }\n")
13442
0
SLANG_RAW("}\n")
13443
0
SLANG_RAW("\n")
13444
0
SLANG_RAW("/// @category math\n")
13445
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
13446
0
SLANG_RAW("[__readNone]\n")
13447
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13448
0
SLANG_RAW("vector<T,N> median3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13449
0
SLANG_RAW("{\n")
13450
0
SLANG_RAW("    __target_switch\n")
13451
0
SLANG_RAW("    {\n")
13452
0
SLANG_RAW("    case metal: __intrinsic_asm \"median3\";\n")
13453
0
SLANG_RAW("    default:\n")
13454
0
SLANG_RAW("    {\n")
13455
0
SLANG_RAW("        vector<T,N> a = min(y, z);\n")
13456
0
SLANG_RAW("        vector<T,N> b = max(y, z);\n")
13457
0
SLANG_RAW("        vector<T,N> c = max(x, a);\n")
13458
0
SLANG_RAW("        vector<T,N> m = min(b, c);\n")
13459
0
SLANG_RAW("        return m;\n")
13460
0
SLANG_RAW("    }\n")
13461
0
SLANG_RAW("    }\n")
13462
0
SLANG_RAW("}\n")
13463
0
SLANG_RAW("\n")
13464
0
SLANG_RAW("/// Floating-point median.\n")
13465
0
SLANG_RAW("/// @param x The first value to compare.\n")
13466
0
SLANG_RAW("/// @param y The second value to compare.\n")
13467
0
SLANG_RAW("/// @param z The third value to compare.\n")
13468
0
SLANG_RAW("/// @return The median of the three values, element-wise if vector typed.\n")
13469
0
SLANG_RAW("/// @remarks For metal, this is implemented with the fmedian3 intrinsic.\n")
13470
0
SLANG_RAW("/// If any value is NaN, it is unspecified which operand is returned.\n")
13471
0
SLANG_RAW("/// @category math\n")
13472
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13473
0
SLANG_RAW("[__readNone]\n")
13474
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13475
0
SLANG_RAW("T fmedian3(T x, T y, T z)\n")
13476
0
SLANG_RAW("{\n")
13477
0
SLANG_RAW("    __target_switch\n")
13478
0
SLANG_RAW("    {\n")
13479
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmedian3\";\n")
13480
0
SLANG_RAW("    default:\n")
13481
0
SLANG_RAW("    {\n")
13482
0
SLANG_RAW("        return median3(x, y, z);\n")
13483
0
SLANG_RAW("    }\n")
13484
0
SLANG_RAW("    }\n")
13485
0
SLANG_RAW("}\n")
13486
0
SLANG_RAW("\n")
13487
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N: int>\n")
13488
0
SLANG_RAW("[__readNone]\n")
13489
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13490
0
SLANG_RAW("vector<T,N> fmedian3(vector<T,N> x, vector<T,N> y, vector<T,N> z)\n")
13491
0
SLANG_RAW("{\n")
13492
0
SLANG_RAW("    __target_switch\n")
13493
0
SLANG_RAW("    {\n")
13494
0
SLANG_RAW("    case metal: __intrinsic_asm \"fmedian3\";\n")
13495
0
SLANG_RAW("    default:\n")
13496
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, fmedian3, x, y, z);\n")
13497
0
SLANG_RAW("    }\n")
13498
0
SLANG_RAW("}\n")
13499
0
SLANG_RAW("\n")
13500
0
SLANG_RAW("/// Split into integer and fractional parts (both with same sign).\n")
13501
0
SLANG_RAW("/// @param x The input value.\n")
13502
0
SLANG_RAW("/// @param[out] ip The integer part of `x`.\n")
13503
0
SLANG_RAW("/// @return The fractional part of `x`.\n")
13504
0
SLANG_RAW("/// @category math\n")
13505
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13506
0
SLANG_RAW("[__readNone]\n")
13507
0
SLANG_RAW("[ForceInline]\n")
13508
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13509
0
SLANG_RAW("T modf(T x, out T ip)\n")
13510
0
SLANG_RAW("{\n")
13511
0
SLANG_RAW("    __target_switch\n")
13512
0
SLANG_RAW("    {\n")
13513
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_modf($0, $1)\";\n")
13514
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_modf($0, $1)\";\n")
13515
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"modf\";\n")
13516
0
SLANG_RAW("    case glsl: __intrinsic_asm \"modf\";\n")
13517
0
SLANG_RAW("    case metal: __intrinsic_asm \"modf($0, *($1))\";\n")
13518
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13519
0
SLANG_RAW("        result:$$T = OpExtInst glsl450 Modf $x &ip\n")
13520
0
SLANG_RAW("    };\n")
13521
0
SLANG_RAW("    case wgsl:\n")
13522
0
SLANG_RAW("        T fract;\n")
13523
0
SLANG_RAW("        __wgsl_modf<T>(x, fract, ip);\n")
13524
0
SLANG_RAW("        return fract;\n")
13525
0
SLANG_RAW("    }\n")
13526
0
SLANG_RAW("}\n")
13527
0
SLANG_RAW("\n")
13528
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13529
0
SLANG_RAW("[__readNone]\n")
13530
0
SLANG_RAW("[ForceInline]\n")
13531
0
SLANG_RAW("[require(wgsl)]\n")
13532
0
SLANG_RAW("void __wgsl_modf(T x, out T fract, out T whole)\n")
13533
0
SLANG_RAW("{\n")
13534
0
SLANG_RAW("    __intrinsic_asm \"{ var s = modf($0); ($1) = s.fract; ($2) = s.whole; }\";\n")
13535
0
SLANG_RAW("}\n")
13536
0
SLANG_RAW("\n")
13537
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13538
0
SLANG_RAW("[__readNone]\n")
13539
0
SLANG_RAW("[ForceInline]\n")
13540
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13541
0
SLANG_RAW("vector<T,N> modf(vector<T,N> x, out vector<T,N> ip)\n")
13542
0
SLANG_RAW("{\n")
13543
0
SLANG_RAW("    __target_switch\n")
13544
0
SLANG_RAW("    {\n")
13545
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"modf\";\n")
13546
0
SLANG_RAW("    case glsl: __intrinsic_asm \"modf\";\n")
13547
0
SLANG_RAW("    case metal: __intrinsic_asm \"modf($0, *($1))\";\n")
13548
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13549
0
SLANG_RAW("        result:$$vector<T,N> = OpExtInst glsl450 Modf $x &ip\n")
13550
0
SLANG_RAW("    };\n")
13551
0
SLANG_RAW("    case wgsl:\n")
13552
0
SLANG_RAW("        vector<T,N> fract;\n")
13553
0
SLANG_RAW("        __wgsl_modf<T>(x, fract, ip);\n")
13554
0
SLANG_RAW("        return fract;\n")
13555
0
SLANG_RAW("    default:\n")
13556
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, modf, x, ip);\n")
13557
0
SLANG_RAW("    }\n")
13558
0
SLANG_RAW("}\n")
13559
0
SLANG_RAW("\n")
13560
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13561
0
SLANG_RAW("[__readNone]\n")
13562
0
SLANG_RAW("[ForceInline]\n")
13563
0
SLANG_RAW("[require(wgsl)]\n")
13564
0
SLANG_RAW("void __wgsl_modf(vector<T,N> x, out vector<T,N> fract, out vector<T,N> whole)\n")
13565
0
SLANG_RAW("{\n")
13566
0
SLANG_RAW("    __intrinsic_asm \"{ var s = modf($0); ($1) = s.fract; ($2) = s.whole; }\";\n")
13567
0
SLANG_RAW("}\n")
13568
0
SLANG_RAW("\n")
13569
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L : int>\n")
13570
0
SLANG_RAW("[__readNone]\n")
13571
0
SLANG_RAW("[ForceInline]\n")
13572
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13573
0
SLANG_RAW("matrix<T,N,M> modf(matrix<T,N,M> x, out matrix<T,N,M,L> ip)\n")
13574
0
SLANG_RAW("{\n")
13575
0
SLANG_RAW("    __target_switch\n")
13576
0
SLANG_RAW("    {\n")
13577
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"modf\";\n")
13578
0
SLANG_RAW("    default:\n")
13579
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, modf, x, ip);\n")
13580
0
SLANG_RAW("    }\n")
13581
0
SLANG_RAW("}\n")
13582
0
SLANG_RAW("\n")
13583
0
SLANG_RAW("/// Masked sum of absolute differences of byte alignments.\n")
13584
0
SLANG_RAW("/// This function computes the absolute differences of the byte alignments of the reference and source values, and adds them to the accumulated differences.\n")
13585
0
SLANG_RAW("/// @param reference The reference 4 bytes packed in a uint.\n")
13586
0
SLANG_RAW("/// @param source The source 2 uints packed in a uint2.\n")
13587
0
SLANG_RAW("/// @param accum The accumulated differences.\n")
13588
0
SLANG_RAW("/// @return The updated accumulated differences.\n")
13589
0
SLANG_RAW("/// @remarks In HLSL, this is implemented with the msad4 intrinsic.\n")
13590
0
SLANG_RAW("/// @category math\n")
13591
0
SLANG_RAW("[__readNone]\n")
13592
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, sm_4_0_version)]\n")
13593
0
SLANG_RAW("uint4 msad4(uint reference, uint2 source, uint4 accum)\n")
13594
0
SLANG_RAW("{\n")
13595
0
SLANG_RAW("    __target_switch\n")
13596
0
SLANG_RAW("    {\n")
13597
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"msad4\";\n")
13598
0
SLANG_RAW("    default:\n")
13599
0
SLANG_RAW("        int4 bytesRef = (reference >> uint4(24, 16, 8, 0)) & 0xFF;\n")
13600
0
SLANG_RAW("        int4 bytesX   = (source.x  >> uint4(24, 16, 8, 0)) & 0xFF;\n")
13601
0
SLANG_RAW("        int4 bytesY   = (source.y  >> uint4(24, 16, 8, 0)) & 0xFF;\n")
13602
0
SLANG_RAW("\n")
13603
0
SLANG_RAW("        uint4 mask = select(bytesRef == 0, 0, 0xFFFFFFFFu);\n")
13604
0
SLANG_RAW("\n")
13605
0
SLANG_RAW("        uint4 result = accum;\n")
13606
0
SLANG_RAW("        result += mask.x & abs(bytesRef - int4(bytesX.x,           bytesY.y, bytesY.z, bytesY.w));\n")
13607
0
SLANG_RAW("        result += mask.y & abs(bytesRef - int4(bytesX.x, bytesX.y,           bytesY.z, bytesY.w));\n")
13608
0
SLANG_RAW("        result += mask.z & abs(bytesRef - int4(bytesX.x, bytesX.y, bytesX.z,           bytesY.w));\n")
13609
0
SLANG_RAW("        result += mask.w & abs(bytesRef - int4(bytesX.x, bytesX.y, bytesX.z, bytesX.w));\n")
13610
0
SLANG_RAW("        return result;\n")
13611
0
SLANG_RAW("    }\n")
13612
0
SLANG_RAW("}\n")
13613
0
SLANG_RAW("\n")
13614
0
SLANG_RAW("// General inner products\n")
13615
0
SLANG_RAW("\n")
13616
0
SLANG_RAW("// scalar-scalar\n")
13617
0
SLANG_RAW("/// Multiply.\n")
13618
0
SLANG_RAW("/// @param x The first value.\n")
13619
0
SLANG_RAW("/// @param y The second value.\n")
13620
0
SLANG_RAW("/// @return The inner product of `x` and `y`.\n")
13621
0
SLANG_RAW("/// @category math\n")
13622
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
13623
0
SLANG_RAW("__intrinsic_op(")
13624
0
SLANG_SPLICE(kIROp_Mul
13625
0
)
13626
0
SLANG_RAW(")\n")
13627
0
SLANG_RAW("[__readNone]\n")
13628
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13629
0
SLANG_RAW("T mul(T x, T y);\n")
13630
0
SLANG_RAW("\n")
13631
0
SLANG_RAW("// scalar-vector and vector-scalar\n")
13632
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
13633
0
SLANG_RAW("__intrinsic_op(")
13634
0
SLANG_SPLICE(kIROp_Mul
13635
0
)
13636
0
SLANG_RAW(")\n")
13637
0
SLANG_RAW("[__readNone]\n")
13638
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13639
0
SLANG_RAW("vector<T, N> mul(vector<T, N> x, T y);\n")
13640
0
SLANG_RAW("\n")
13641
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
13642
0
SLANG_RAW("__intrinsic_op(")
13643
0
SLANG_SPLICE(kIROp_Mul
13644
0
)
13645
0
SLANG_RAW(")\n")
13646
0
SLANG_RAW("[__readNone]\n")
13647
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13648
0
SLANG_RAW("vector<T, N> mul(T x, vector<T, N> y);\n")
13649
0
SLANG_RAW("\n")
13650
0
SLANG_RAW("// scalar-matrix and matrix-scalar\n")
13651
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M :int>\n")
13652
0
SLANG_RAW("__intrinsic_op(")
13653
0
SLANG_SPLICE(kIROp_Mul
13654
0
)
13655
0
SLANG_RAW(")\n")
13656
0
SLANG_RAW("[__readNone]\n")
13657
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13658
0
SLANG_RAW("matrix<T, N, M> mul(matrix<T, N, M> x, T y);\n")
13659
0
SLANG_RAW("\n")
13660
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M :int>\n")
13661
0
SLANG_RAW("__intrinsic_op(")
13662
0
SLANG_SPLICE(kIROp_Mul
13663
0
)
13664
0
SLANG_RAW(")\n")
13665
0
SLANG_RAW("[__readNone]\n")
13666
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
13667
0
SLANG_RAW("matrix<T, N, M> mul(T x, matrix<T, N, M> y);\n")
13668
0
SLANG_RAW("\n")
13669
0
SLANG_RAW("// vector-vector (dot product)\n")
13670
0
SLANG_RAW("/// @category math\n")
13671
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13672
0
SLANG_RAW("[__readNone]\n")
13673
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13674
0
SLANG_RAW("T mul(vector<T, N> x, vector<T, N> y)\n")
13675
0
SLANG_RAW("{\n")
13676
0
SLANG_RAW("    __target_switch\n")
13677
0
SLANG_RAW("    {\n")
13678
0
SLANG_RAW("    case glsl: __intrinsic_asm \"dot\";\n")
13679
0
SLANG_RAW("    case metal: __intrinsic_asm \"dot\";\n")
13680
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13681
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"dot\";\n")
13682
0
SLANG_RAW("    default:\n")
13683
0
SLANG_RAW("        return dot(x, y);\n")
13684
0
SLANG_RAW("    }\n")
13685
0
SLANG_RAW("}\n")
13686
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int>\n")
13687
0
SLANG_RAW("[__readNone]\n")
13688
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13689
0
SLANG_RAW("T mul(vector<T, N> x, vector<T, N> y)\n")
13690
0
SLANG_RAW("{\n")
13691
0
SLANG_RAW("    __target_switch\n")
13692
0
SLANG_RAW("    {\n")
13693
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13694
0
SLANG_RAW("    default:\n")
13695
0
SLANG_RAW("        return dot(x, y);\n")
13696
0
SLANG_RAW("    }\n")
13697
0
SLANG_RAW("}\n")
13698
0
SLANG_RAW("\n")
13699
0
SLANG_RAW("// vector-matrix\n")
13700
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
13701
0
SLANG_RAW("[__readNone]\n")
13702
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13703
0
SLANG_RAW("vector<T, M> mul(vector<T, N> left, matrix<T, N, M> right)\n")
13704
0
SLANG_RAW("{\n")
13705
0
SLANG_RAW("    __target_switch\n")
13706
0
SLANG_RAW("    {\n")
13707
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13708
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13709
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13710
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13711
0
SLANG_RAW("        OpMatrixTimesVector $$vector<T, M> result $right $left\n")
13712
0
SLANG_RAW("    };\n")
13713
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13714
0
SLANG_RAW("    default:\n")
13715
0
SLANG_RAW("        vector<T,M> result;\n")
13716
0
SLANG_RAW("        for( int j = 0; j < M; ++j )\n")
13717
0
SLANG_RAW("        {\n")
13718
0
SLANG_RAW("            T sum = T(0);\n")
13719
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13720
0
SLANG_RAW("            {\n")
13721
0
SLANG_RAW("                sum += left[i] * right[i][j];\n")
13722
0
SLANG_RAW("            }\n")
13723
0
SLANG_RAW("            result[j] = sum;\n")
13724
0
SLANG_RAW("        }\n")
13725
0
SLANG_RAW("        return result;\n")
13726
0
SLANG_RAW("    }\n")
13727
0
SLANG_RAW("}\n")
13728
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
13729
0
SLANG_RAW("[__readNone]\n")
13730
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13731
0
SLANG_RAW("vector<T, M> mul(vector<T, N> left, matrix<T, N, M> right)\n")
13732
0
SLANG_RAW("{\n")
13733
0
SLANG_RAW("    __target_switch\n")
13734
0
SLANG_RAW("    {\n")
13735
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13736
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13737
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13738
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13739
0
SLANG_RAW("    default:\n")
13740
0
SLANG_RAW("        vector<T,M> result;\n")
13741
0
SLANG_RAW("        for( int j = 0; j < M; ++j )\n")
13742
0
SLANG_RAW("        {\n")
13743
0
SLANG_RAW("            T sum = T(0);\n")
13744
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13745
0
SLANG_RAW("            {\n")
13746
0
SLANG_RAW("                sum += left[i] * right[i][j];\n")
13747
0
SLANG_RAW("            }\n")
13748
0
SLANG_RAW("            result[j] = sum;\n")
13749
0
SLANG_RAW("        }\n")
13750
0
SLANG_RAW("        return result;\n")
13751
0
SLANG_RAW("    }\n")
13752
0
SLANG_RAW("}\n")
13753
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
13754
0
SLANG_RAW("[__readNone]\n")
13755
0
SLANG_RAW("[OverloadRank(-1)]\n")
13756
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13757
0
SLANG_RAW("vector<T, M> mul(vector<T, N> left, matrix<T, N, M> right)\n")
13758
0
SLANG_RAW("{\n")
13759
0
SLANG_RAW("    __target_switch\n")
13760
0
SLANG_RAW("    {\n")
13761
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13762
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13763
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13764
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13765
0
SLANG_RAW("    default:\n")
13766
0
SLANG_RAW("        vector<T,M> result;\n")
13767
0
SLANG_RAW("        for( int j = 0; j < M; ++j )\n")
13768
0
SLANG_RAW("        {\n")
13769
0
SLANG_RAW("            T sum = T(0);\n")
13770
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13771
0
SLANG_RAW("            {\n")
13772
0
SLANG_RAW("                sum |= left[i] & right[i][j];\n")
13773
0
SLANG_RAW("            }\n")
13774
0
SLANG_RAW("            result[j] = sum;\n")
13775
0
SLANG_RAW("        }\n")
13776
0
SLANG_RAW("        return result;\n")
13777
0
SLANG_RAW("    }\n")
13778
0
SLANG_RAW("}\n")
13779
0
SLANG_RAW("\n")
13780
0
SLANG_RAW("// matrix-vector\n")
13781
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
13782
0
SLANG_RAW("[__readNone]\n")
13783
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13784
0
SLANG_RAW("vector<T,N> mul(matrix<T,N,M> left, vector<T,M> right)\n")
13785
0
SLANG_RAW("{\n")
13786
0
SLANG_RAW("    __target_switch\n")
13787
0
SLANG_RAW("    {\n")
13788
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13789
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13790
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13791
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13792
0
SLANG_RAW("        OpVectorTimesMatrix $$vector<T,N> result $right $left\n")
13793
0
SLANG_RAW("    };\n")
13794
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13795
0
SLANG_RAW("    default:\n")
13796
0
SLANG_RAW("        vector<T,N> result;\n")
13797
0
SLANG_RAW("        for( int i = 0; i < N; ++i )\n")
13798
0
SLANG_RAW("        {\n")
13799
0
SLANG_RAW("            T sum = T(0);\n")
13800
0
SLANG_RAW("            for( int j = 0; j < M; ++j )\n")
13801
0
SLANG_RAW("            {\n")
13802
0
SLANG_RAW("                sum += left[i][j] * right[j];\n")
13803
0
SLANG_RAW("            }\n")
13804
0
SLANG_RAW("            result[i] = sum;\n")
13805
0
SLANG_RAW("        }\n")
13806
0
SLANG_RAW("        return result;\n")
13807
0
SLANG_RAW("    }\n")
13808
0
SLANG_RAW("}\n")
13809
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
13810
0
SLANG_RAW("[__readNone]\n")
13811
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13812
0
SLANG_RAW("vector<T,N> mul(matrix<T,N,M> left, vector<T,M> right)\n")
13813
0
SLANG_RAW("{\n")
13814
0
SLANG_RAW("    __target_switch\n")
13815
0
SLANG_RAW("    {\n")
13816
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13817
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13818
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13819
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13820
0
SLANG_RAW("    default:\n")
13821
0
SLANG_RAW("        vector<T,N> result;\n")
13822
0
SLANG_RAW("        for( int i = 0; i < N; ++i )\n")
13823
0
SLANG_RAW("        {\n")
13824
0
SLANG_RAW("            T sum = T(0);\n")
13825
0
SLANG_RAW("            for( int j = 0; j < M; ++j )\n")
13826
0
SLANG_RAW("            {\n")
13827
0
SLANG_RAW("                sum += left[i][j] * right[j];\n")
13828
0
SLANG_RAW("            }\n")
13829
0
SLANG_RAW("            result[i] = sum;\n")
13830
0
SLANG_RAW("        }\n")
13831
0
SLANG_RAW("        return result;\n")
13832
0
SLANG_RAW("    }\n")
13833
0
SLANG_RAW("}\n")
13834
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
13835
0
SLANG_RAW("[__readNone]\n")
13836
0
SLANG_RAW("[OverloadRank(-1)]\n")
13837
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13838
0
SLANG_RAW("vector<T,N> mul(matrix<T,N,M> left, vector<T,M> right)\n")
13839
0
SLANG_RAW("{\n")
13840
0
SLANG_RAW("    __target_switch\n")
13841
0
SLANG_RAW("    {\n")
13842
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13843
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13844
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13845
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13846
0
SLANG_RAW("    default:\n")
13847
0
SLANG_RAW("        vector<T,N> result;\n")
13848
0
SLANG_RAW("        for( int i = 0; i < N; ++i )\n")
13849
0
SLANG_RAW("        {\n")
13850
0
SLANG_RAW("            T sum = T(0);\n")
13851
0
SLANG_RAW("            for( int j = 0; j < M; ++j )\n")
13852
0
SLANG_RAW("            {\n")
13853
0
SLANG_RAW("                sum |= left[i][j] & right[j];\n")
13854
0
SLANG_RAW("            }\n")
13855
0
SLANG_RAW("            result[i] = sum;\n")
13856
0
SLANG_RAW("        }\n")
13857
0
SLANG_RAW("        return result;\n")
13858
0
SLANG_RAW("    }\n")
13859
0
SLANG_RAW("}\n")
13860
0
SLANG_RAW("\n")
13861
0
SLANG_RAW("// matrix-matrix\n")
13862
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let R : int, let N : int, let C : int>\n")
13863
0
SLANG_RAW("[__readNone]\n")
13864
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13865
0
SLANG_RAW("matrix<T,R,C> mul(matrix<T,R,N> left, matrix<T,N,C> right)\n")
13866
0
SLANG_RAW("{\n")
13867
0
SLANG_RAW("    __target_switch\n")
13868
0
SLANG_RAW("    {\n")
13869
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13870
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13871
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13872
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
13873
0
SLANG_RAW("        OpMatrixTimesMatrix $$matrix<T,R,C> result $right $left\n")
13874
0
SLANG_RAW("    };\n")
13875
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13876
0
SLANG_RAW("    default:\n")
13877
0
SLANG_RAW("        matrix<T,R,C> result;\n")
13878
0
SLANG_RAW("        for( int r = 0; r < R; ++r)\n")
13879
0
SLANG_RAW("        for( int c = 0; c < C; ++c)\n")
13880
0
SLANG_RAW("        {\n")
13881
0
SLANG_RAW("            T sum = T(0);\n")
13882
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13883
0
SLANG_RAW("            {\n")
13884
0
SLANG_RAW("                sum += left[r][i] * right[i][c];\n")
13885
0
SLANG_RAW("            }\n")
13886
0
SLANG_RAW("            result[r][c] = sum;\n")
13887
0
SLANG_RAW("        }\n")
13888
0
SLANG_RAW("        return result;\n")
13889
0
SLANG_RAW("    }\n")
13890
0
SLANG_RAW("}\n")
13891
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let R : int, let N : int, let C : int>\n")
13892
0
SLANG_RAW("[__readNone]\n")
13893
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13894
0
SLANG_RAW("matrix<T,R,C> mul(matrix<T,R,N> left, matrix<T,N,C> right)\n")
13895
0
SLANG_RAW("{\n")
13896
0
SLANG_RAW("    __target_switch\n")
13897
0
SLANG_RAW("    {\n")
13898
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13899
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13900
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13901
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13902
0
SLANG_RAW("    default:\n")
13903
0
SLANG_RAW("        matrix<T,R,C> result;\n")
13904
0
SLANG_RAW("        for( int r = 0; r < R; ++r)\n")
13905
0
SLANG_RAW("        for( int c = 0; c < C; ++c)\n")
13906
0
SLANG_RAW("        {\n")
13907
0
SLANG_RAW("            T sum = T(0);\n")
13908
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13909
0
SLANG_RAW("            {\n")
13910
0
SLANG_RAW("                sum += left[r][i] * right[i][c];\n")
13911
0
SLANG_RAW("            }\n")
13912
0
SLANG_RAW("            result[r][c] = sum;\n")
13913
0
SLANG_RAW("        }\n")
13914
0
SLANG_RAW("        return result;\n")
13915
0
SLANG_RAW("    }\n")
13916
0
SLANG_RAW("}\n")
13917
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let R : int, let N : int, let C : int>\n")
13918
0
SLANG_RAW("[__readNone]\n")
13919
0
SLANG_RAW("[OverloadRank(-1)]\n")
13920
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
13921
0
SLANG_RAW("matrix<T,R,C> mul(matrix<T,R,N> left, matrix<T,N,C> right)\n")
13922
0
SLANG_RAW("{\n")
13923
0
SLANG_RAW("    __target_switch\n")
13924
0
SLANG_RAW("    {\n")
13925
0
SLANG_RAW("    case glsl: __intrinsic_asm \"($1 * $0)\";\n")
13926
0
SLANG_RAW("    case metal: __intrinsic_asm \"($1 * $0)\";\n")
13927
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"mul\";\n")
13928
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"($1 * $0)\";\n")
13929
0
SLANG_RAW("    default:\n")
13930
0
SLANG_RAW("        matrix<T,R,C> result;\n")
13931
0
SLANG_RAW("        for( int r = 0; r < R; ++r)\n")
13932
0
SLANG_RAW("        for( int c = 0; c < C; ++c)\n")
13933
0
SLANG_RAW("        {\n")
13934
0
SLANG_RAW("            T sum = T(0);\n")
13935
0
SLANG_RAW("            for( int i = 0; i < N; ++i )\n")
13936
0
SLANG_RAW("            {\n")
13937
0
SLANG_RAW("                sum |= left[r][i] & right[i][c];\n")
13938
0
SLANG_RAW("            }\n")
13939
0
SLANG_RAW("            result[r][c] = sum;\n")
13940
0
SLANG_RAW("        }\n")
13941
0
SLANG_RAW("        return result;\n")
13942
0
SLANG_RAW("    }\n")
13943
0
SLANG_RAW("}\n")
13944
0
SLANG_RAW("\n")
13945
0
SLANG_RAW("// next-after: next representable floating-point value\n")
13946
0
SLANG_RAW("// after x in the direction of y\n")
13947
0
SLANG_RAW("\n")
13948
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
13949
0
SLANG_RAW("[__readNone]\n")
13950
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_4_0)]\n")
13951
0
SLANG_RAW("T nextafter(T x, T y)\n")
13952
0
SLANG_RAW("{\n")
13953
0
SLANG_RAW("    __target_switch\n")
13954
0
SLANG_RAW("    {\n")
13955
0
SLANG_RAW("    case metal: __intrinsic_asm \"nextafter\";\n")
13956
0
SLANG_RAW("    default:\n")
13957
0
SLANG_RAW("        if (isnan(x)) return x;\n")
13958
0
SLANG_RAW("        if (isnan(y)) return y;\n")
13959
0
SLANG_RAW("        if (x == y) return y;\n")
13960
0
SLANG_RAW("\n")
13961
0
SLANG_RAW("        int delta = x < y ? 1 : -1;\n")
13962
0
SLANG_RAW("\n")
13963
0
SLANG_RAW("        if (T is half)\n")
13964
0
SLANG_RAW("        {\n")
13965
0
SLANG_RAW("            uint16_t val = bit_cast<uint16_t>(x);\n")
13966
0
SLANG_RAW("            if((val >> 15) != 0) // If we're negative, -1 acts like +1 on the float.\n")
13967
0
SLANG_RAW("                delta = -delta;\n")
13968
0
SLANG_RAW("            uint16_t nextval = val + uint16_t(delta);\n")
13969
0
SLANG_RAW("            if(((val^nextval) >> 15) != 0) // If sign bit changed\n")
13970
0
SLANG_RAW("                nextval += 0x8002; // Correct the overflow\n")
13971
0
SLANG_RAW("            return bit_cast<T>(nextval);\n")
13972
0
SLANG_RAW("        }\n")
13973
0
SLANG_RAW("        if (T is float)\n")
13974
0
SLANG_RAW("        {\n")
13975
0
SLANG_RAW("            uint32_t val = bit_cast<uint32_t>(x);\n")
13976
0
SLANG_RAW("            if((val >> 31) != 0)\n")
13977
0
SLANG_RAW("                delta = -delta;\n")
13978
0
SLANG_RAW("            uint32_t nextval = val + uint32_t(delta);\n")
13979
0
SLANG_RAW("            if(((val^nextval) >> 31) != 0)\n")
13980
0
SLANG_RAW("                nextval += 0x80000002u;\n")
13981
0
SLANG_RAW("            return bit_cast<T>(nextval);\n")
13982
0
SLANG_RAW("        }\n")
13983
0
SLANG_RAW("        uint64_t val = bit_cast<uint64_t>(x);\n")
13984
0
SLANG_RAW("        if((val >> 63) != 0)\n")
13985
0
SLANG_RAW("            delta = -delta;\n")
13986
0
SLANG_RAW("        uint64_t nextval = val + uint64_t(delta);\n")
13987
0
SLANG_RAW("        if(((val^nextval) >> 63) != 0)\n")
13988
0
SLANG_RAW("            nextval += 0x8000000000000002ull;\n")
13989
0
SLANG_RAW("        return bit_cast<T>(nextval);\n")
13990
0
SLANG_RAW("    }\n")
13991
0
SLANG_RAW("}\n")
13992
0
SLANG_RAW("\n")
13993
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
13994
0
SLANG_RAW("[__readNone]\n")
13995
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, shader5_sm_4_0)]\n")
13996
0
SLANG_RAW("vector<T,N> nextafter(vector<T,N> x, vector<T,N> y)\n")
13997
0
SLANG_RAW("{\n")
13998
0
SLANG_RAW("    __target_switch\n")
13999
0
SLANG_RAW("    {\n")
14000
0
SLANG_RAW("    case metal: __intrinsic_asm \"nextafter\";\n")
14001
0
SLANG_RAW("    default:\n")
14002
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, nextafter, x, y);\n")
14003
0
SLANG_RAW("    }\n")
14004
0
SLANG_RAW("}\n")
14005
0
SLANG_RAW("\n")
14006
0
SLANG_RAW("/// Indicate that an index may be non-uniform at execution time.\n")
14007
0
SLANG_RAW("///\n")
14008
0
SLANG_RAW("/// Shader Model 5.1 and 6.x introduce support for dynamic indexing\n")
14009
0
SLANG_RAW("/// of arrays of resources, but place the restriction that *by default*\n")
14010
0
SLANG_RAW("/// the implementation can assume that any value used as an index into\n")
14011
0
SLANG_RAW("/// such arrays will be dynamically uniform across an entire `Draw` or `Dispatch`\n")
14012
0
SLANG_RAW("/// (when using instancing, the value must be uniform across all instances;\n")
14013
0
SLANG_RAW("/// it does not seem that the restriction extends to draws within a multi-draw).\n")
14014
0
SLANG_RAW("///\n")
14015
0
SLANG_RAW("/// In order to indicate to the implementation that it cannot make the\n")
14016
0
SLANG_RAW("/// uniformity assumption, a shader programmer is required to pass the index\n")
14017
0
SLANG_RAW("/// to the `NonUniformResourceIndex` function before using it as an index.\n")
14018
0
SLANG_RAW("/// The function superficially acts like an identity function.\n")
14019
0
SLANG_RAW("///\n")
14020
0
SLANG_RAW("/// Note: a future version of Slang may take responsibility for inserting calls\n")
14021
0
SLANG_RAW("/// to this function as necessary in output code, rather than make this\n")
14022
0
SLANG_RAW("/// the user's responsibility, so that the default behavior of the language\n")
14023
0
SLANG_RAW("/// is more semantically \"correct.\"\n")
14024
0
SLANG_RAW("[ForceInline]\n")
14025
0
SLANG_RAW("[require(spirv)]\n")
14026
0
SLANG_RAW("T __copyObject<T>(T v)\n")
14027
0
SLANG_RAW("{\n")
14028
0
SLANG_RAW("    __target_switch {\n")
14029
0
SLANG_RAW("    case spirv:\n")
14030
0
SLANG_RAW("        return spirv_asm {\n")
14031
0
SLANG_RAW("           result:$$T = OpCopyObject $v;\n")
14032
0
SLANG_RAW("        };\n")
14033
0
SLANG_RAW("   }\n")
14034
0
SLANG_RAW("}\n")
14035
0
SLANG_RAW("\n")
14036
0
SLANG_RAW("/// `NonUniformResourceIndex` function is used to indicate if the resource index is\n")
14037
0
SLANG_RAW("/// divergent, and ensure scalarization happens correctly for each divergent lane.\n")
14038
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType>\n")
14039
0
SLANG_RAW("__intrinsic_op(")
14040
0
SLANG_SPLICE(kIROp_NonUniformResourceIndex
14041
0
)
14042
0
SLANG_RAW(")\n")
14043
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, nonuniformqualifier)]\n")
14044
0
SLANG_RAW("T NonUniformResourceIndex(T index);\n")
14045
0
SLANG_RAW("\n")
14046
0
SLANG_RAW("/// HLSL allows NonUniformResourceIndex around non int/uint types.\n")
14047
0
SLANG_RAW("/// It's effect is presumably to ignore it, which the following implementation does.\n")
14048
0
SLANG_RAW("/// We should also look to add a warning for this scenario.\n")
14049
0
SLANG_RAW("/// @deprecated\n")
14050
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
14051
0
SLANG_RAW("[deprecated(\"NonUniformResourceIndex on a type other than uint/int is deprecated and has no effect\")]\n")
14052
0
SLANG_RAW("T NonUniformResourceIndex<T>(T value) { return value; }\n")
14053
0
SLANG_RAW("\n")
14054
0
SLANG_RAW("/// Normalize a vector.\n")
14055
0
SLANG_RAW("/// @param x The vector to normalize.\n")
14056
0
SLANG_RAW("/// @return The normalized vector, `x`/`length(x)`.\n")
14057
0
SLANG_RAW("/// @category math\n")
14058
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14059
0
SLANG_RAW("[__readNone]\n")
14060
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14061
0
SLANG_RAW("vector<T,N> normalize(vector<T,N> x)\n")
14062
0
SLANG_RAW("{\n")
14063
0
SLANG_RAW("    __target_switch\n")
14064
0
SLANG_RAW("    {\n")
14065
0
SLANG_RAW("    case glsl: __intrinsic_asm \"normalize\";\n")
14066
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"normalize\";\n")
14067
0
SLANG_RAW("    case metal: __intrinsic_asm \"normalize\";\n")
14068
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14069
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Normalize $x\n")
14070
0
SLANG_RAW("    };\n")
14071
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"normalize\";\n")
14072
0
SLANG_RAW("    default:\n")
14073
0
SLANG_RAW("        return x / length(x);\n")
14074
0
SLANG_RAW("    }\n")
14075
0
SLANG_RAW("}\n")
14076
0
SLANG_RAW("\n")
14077
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14078
0
SLANG_RAW("[__readNone]\n")
14079
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14080
0
SLANG_RAW("T normalize(T x)\n")
14081
0
SLANG_RAW("{\n")
14082
0
SLANG_RAW("    __target_switch\n")
14083
0
SLANG_RAW("    {\n")
14084
0
SLANG_RAW("    case glsl: __intrinsic_asm \"normalize\";\n")
14085
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"normalize\";\n")
14086
0
SLANG_RAW("    case metal: __intrinsic_asm \"normalize\";\n")
14087
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14088
0
SLANG_RAW("        OpExtInst $$T result glsl450 Normalize $x\n")
14089
0
SLANG_RAW("    };\n")
14090
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"normalize\";\n")
14091
0
SLANG_RAW("    default:\n")
14092
0
SLANG_RAW("        return x / length(x);\n")
14093
0
SLANG_RAW("    }\n")
14094
0
SLANG_RAW("}\n")
14095
0
SLANG_RAW("\n")
14096
0
SLANG_RAW("/// Raise to a power.\n")
14097
0
SLANG_RAW("/// @param x The base value.\n")
14098
0
SLANG_RAW("/// @param y The exponent value.\n")
14099
0
SLANG_RAW("/// @return The value of `x` raised to the power of `y`.\n")
14100
0
SLANG_RAW("/// @category math\n")
14101
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14102
0
SLANG_RAW("[__readNone]\n")
14103
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14104
0
SLANG_RAW("T pow(T x, T y)\n")
14105
0
SLANG_RAW("{\n")
14106
0
SLANG_RAW("    __target_switch\n")
14107
0
SLANG_RAW("    {\n")
14108
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_pow($0, $1)\";\n")
14109
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_pow($0, $1)\";\n")
14110
0
SLANG_RAW("    case glsl: __intrinsic_asm \"pow\";\n")
14111
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pow\";\n")
14112
0
SLANG_RAW("    case metal: __intrinsic_asm \"pow\";\n")
14113
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14114
0
SLANG_RAW("        OpExtInst $$T result glsl450 Pow $x $y\n")
14115
0
SLANG_RAW("    };\n")
14116
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pow\";\n")
14117
0
SLANG_RAW("    }\n")
14118
0
SLANG_RAW("}\n")
14119
0
SLANG_RAW("\n")
14120
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14121
0
SLANG_RAW("[__readNone]\n")
14122
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14123
0
SLANG_RAW("vector<T, N> pow(vector<T, N> x, vector<T, N> y)\n")
14124
0
SLANG_RAW("{\n")
14125
0
SLANG_RAW("    __target_switch\n")
14126
0
SLANG_RAW("    {\n")
14127
0
SLANG_RAW("    case glsl: __intrinsic_asm \"pow\";\n")
14128
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pow\";\n")
14129
0
SLANG_RAW("    case metal: __intrinsic_asm \"pow\";\n")
14130
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14131
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Pow $x $y\n")
14132
0
SLANG_RAW("    };\n")
14133
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pow\";\n")
14134
0
SLANG_RAW("    default:\n")
14135
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, pow, x, y);\n")
14136
0
SLANG_RAW("    }\n")
14137
0
SLANG_RAW("}\n")
14138
0
SLANG_RAW("\n")
14139
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14140
0
SLANG_RAW("[__readNone]\n")
14141
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14142
0
SLANG_RAW("matrix<T,N,M> pow(matrix<T,N,M> x, matrix<T,N,M> y)\n")
14143
0
SLANG_RAW("{\n")
14144
0
SLANG_RAW("    __target_switch\n")
14145
0
SLANG_RAW("    {\n")
14146
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pow\";\n")
14147
0
SLANG_RAW("    default:\n")
14148
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, pow, x, y);\n")
14149
0
SLANG_RAW("    }\n")
14150
0
SLANG_RAW("}\n")
14151
0
SLANG_RAW("\n")
14152
0
SLANG_RAW("/// Raise positive base value to a power.\n")
14153
0
SLANG_RAW("/// @param x The base value, must be >= 0.\n")
14154
0
SLANG_RAW("/// @param y The exponent value.\n")
14155
0
SLANG_RAW("/// @return The value of `x` raised to the power of `y`.\n")
14156
0
SLANG_RAW("/// @category math\n")
14157
0
SLANG_RAW("/// @remarks Return value is undefined for non-positive values of `x`.\n")
14158
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14159
0
SLANG_RAW("[__readNone]\n")
14160
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14161
0
SLANG_RAW("T powr(T x, T y)\n")
14162
0
SLANG_RAW("{\n")
14163
0
SLANG_RAW("    __target_switch\n")
14164
0
SLANG_RAW("    {\n")
14165
0
SLANG_RAW("    case metal: __intrinsic_asm \"powr\";\n")
14166
0
SLANG_RAW("    default:\n")
14167
0
SLANG_RAW("        return pow(x, y);\n")
14168
0
SLANG_RAW("    }\n")
14169
0
SLANG_RAW("}\n")
14170
0
SLANG_RAW("\n")
14171
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14172
0
SLANG_RAW("[__readNone]\n")
14173
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14174
0
SLANG_RAW("vector<T, N> powr(vector<T, N> x, vector<T, N> y)\n")
14175
0
SLANG_RAW("{\n")
14176
0
SLANG_RAW("    __target_switch\n")
14177
0
SLANG_RAW("    {\n")
14178
0
SLANG_RAW("    case metal: __intrinsic_asm \"powr\";\n")
14179
0
SLANG_RAW("    default:\n")
14180
0
SLANG_RAW("        return pow(x, y);\n")
14181
0
SLANG_RAW("    }\n")
14182
0
SLANG_RAW("}\n")
14183
0
SLANG_RAW("\n")
14184
0
SLANG_RAW("// Output message\n")
14185
0
SLANG_RAW("// TODO: add check to ensure format is const literal.\n")
14186
0
SLANG_RAW("\n")
14187
0
SLANG_RAW("/// Print a message to the debug output.\n")
14188
0
SLANG_RAW("/// @param T The variadic type pack parameter for the arguments to be printed.\n")
14189
0
SLANG_RAW("/// @param format The format string.\n")
14190
0
SLANG_RAW("/// @param args (optional) The arguments to be printed.\n")
14191
0
SLANG_RAW("/// @remarks The function maps to `printf` for HLSL, CPU and CUDA targets, and maps to `OpDebugPrintf` for SPIR-V target,\n")
14192
0
SLANG_RAW("/// and maps to `debugPrintfEXT` for GLSL target. Depending on the target and execution environment, the function may have\n")
14193
0
SLANG_RAW("/// no effect.\n")
14194
0
SLANG_RAW("/// @example\n")
14195
0
SLANG_RAW("/// ```cpp\n")
14196
0
SLANG_RAW("/// void test(int x, float y)\n")
14197
0
SLANG_RAW("/// {\n")
14198
0
SLANG_RAW("///     printf(\"hello world!\\n\");\n")
14199
0
SLANG_RAW("///     printf(R\"(x = \"%d\", y = \"%f\")\", x, y);\n")
14200
0
SLANG_RAW("/// }\n")
14201
0
SLANG_RAW("/// ```\n")
14202
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, printf)]\n")
14203
0
SLANG_RAW("[require(slangvm)]\n")
14204
0
SLANG_RAW("__intrinsic_op(")
14205
0
SLANG_SPLICE(kIROp_Printf
14206
0
)
14207
0
SLANG_RAW(")\n")
14208
0
SLANG_RAW("void printf<each T>(NativeString format, expand each T args);\n")
14209
0
SLANG_RAW("\n")
14210
0
SLANG_RAW("// Tessellation factor fixup routines\n")
14211
0
SLANG_RAW("/// @category tessellation Tessellation functions\n")
14212
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14213
0
SLANG_RAW("void Process2DQuadTessFactorsAvg(\n")
14214
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14215
0
SLANG_RAW("    in  float2 InsideScale,\n")
14216
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14217
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14218
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14219
0
SLANG_RAW("\n")
14220
0
SLANG_RAW("/// @category tessellation\n")
14221
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14222
0
SLANG_RAW("void Process2DQuadTessFactorsMax(\n")
14223
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14224
0
SLANG_RAW("    in  float2 InsideScale,\n")
14225
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14226
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14227
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14228
0
SLANG_RAW("\n")
14229
0
SLANG_RAW("/// @category tessellation\n")
14230
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14231
0
SLANG_RAW("void Process2DQuadTessFactorsMin(\n")
14232
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14233
0
SLANG_RAW("    in  float2 InsideScale,\n")
14234
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14235
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14236
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14237
0
SLANG_RAW("\n")
14238
0
SLANG_RAW("/// @category tessellation\n")
14239
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14240
0
SLANG_RAW("void ProcessIsolineTessFactors(\n")
14241
0
SLANG_RAW("    in  float RawDetailFactor,\n")
14242
0
SLANG_RAW("    in  float RawDensityFactor,\n")
14243
0
SLANG_RAW("    out float RoundedDetailFactor,\n")
14244
0
SLANG_RAW("    out float RoundedDensityFactor);\n")
14245
0
SLANG_RAW("\n")
14246
0
SLANG_RAW("/// @category tessellation\n")
14247
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14248
0
SLANG_RAW("void ProcessQuadTessFactorsAvg(\n")
14249
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14250
0
SLANG_RAW("    in  float InsideScale,\n")
14251
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14252
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14253
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14254
0
SLANG_RAW("\n")
14255
0
SLANG_RAW("/// @category tessellation\n")
14256
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14257
0
SLANG_RAW("void ProcessQuadTessFactorsMax(\n")
14258
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14259
0
SLANG_RAW("    in  float InsideScale,\n")
14260
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14261
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14262
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14263
0
SLANG_RAW("\n")
14264
0
SLANG_RAW("/// @category tessellation\n")
14265
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14266
0
SLANG_RAW("void ProcessQuadTessFactorsMin(\n")
14267
0
SLANG_RAW("    in  float4 RawEdgeFactors,\n")
14268
0
SLANG_RAW("    in  float InsideScale,\n")
14269
0
SLANG_RAW("    out float4 RoundedEdgeTessFactors,\n")
14270
0
SLANG_RAW("    out float2 RoundedInsideTessFactors,\n")
14271
0
SLANG_RAW("    out float2 UnroundedInsideTessFactors);\n")
14272
0
SLANG_RAW("\n")
14273
0
SLANG_RAW("/// @category tessellation\n")
14274
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14275
0
SLANG_RAW("void ProcessTriTessFactorsAvg(\n")
14276
0
SLANG_RAW("    in  float3 RawEdgeFactors,\n")
14277
0
SLANG_RAW("    in  float InsideScale,\n")
14278
0
SLANG_RAW("    out float3 RoundedEdgeTessFactors,\n")
14279
0
SLANG_RAW("    out float RoundedInsideTessFactor,\n")
14280
0
SLANG_RAW("    out float UnroundedInsideTessFactor);\n")
14281
0
SLANG_RAW("\n")
14282
0
SLANG_RAW("/// @category tessellation\n")
14283
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14284
0
SLANG_RAW("void ProcessTriTessFactorsMax(\n")
14285
0
SLANG_RAW("    in  float3 RawEdgeFactors,\n")
14286
0
SLANG_RAW("    in  float InsideScale,\n")
14287
0
SLANG_RAW("    out float3 RoundedEdgeTessFactors,\n")
14288
0
SLANG_RAW("    out float RoundedInsideTessFactor,\n")
14289
0
SLANG_RAW("    out float UnroundedInsideTessFactor);\n")
14290
0
SLANG_RAW("\n")
14291
0
SLANG_RAW("/// @category tessellation\n")
14292
0
SLANG_RAW("[require(hlsl, sm_5_0)]\n")
14293
0
SLANG_RAW("void ProcessTriTessFactorsMin(\n")
14294
0
SLANG_RAW("    in  float3 RawEdgeFactors,\n")
14295
0
SLANG_RAW("    in  float InsideScale,\n")
14296
0
SLANG_RAW("    out float3 RoundedEdgeTessFactors,\n")
14297
0
SLANG_RAW("    out float RoundedInsideTessFactors,\n")
14298
0
SLANG_RAW("    out float UnroundedInsideTessFactors);\n")
14299
0
SLANG_RAW("\n")
14300
0
SLANG_RAW("/// Convert degrees to radians.\n")
14301
0
SLANG_RAW("/// @param x The angle in degrees.\n")
14302
0
SLANG_RAW("/// @return The angle in radians.\n")
14303
0
SLANG_RAW("/// @category math\n")
14304
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14305
0
SLANG_RAW("[__readNone]\n")
14306
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14307
0
SLANG_RAW("T radians(T x)\n")
14308
0
SLANG_RAW("{\n")
14309
0
SLANG_RAW("    __target_switch\n")
14310
0
SLANG_RAW("    {\n")
14311
0
SLANG_RAW("    case glsl: __intrinsic_asm \"radians\";\n")
14312
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"radians\";\n")
14313
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14314
0
SLANG_RAW("        OpExtInst $$T result glsl450 Radians $x\n")
14315
0
SLANG_RAW("    };\n")
14316
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"radians\";\n")
14317
0
SLANG_RAW("    default:\n")
14318
0
SLANG_RAW("        return x * (T.getPi() / T(180.0f));\n")
14319
0
SLANG_RAW("    }\n")
14320
0
SLANG_RAW("}\n")
14321
0
SLANG_RAW("\n")
14322
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14323
0
SLANG_RAW("[__readNone]\n")
14324
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14325
0
SLANG_RAW("vector<T, N> radians(vector<T, N> x)\n")
14326
0
SLANG_RAW("{\n")
14327
0
SLANG_RAW("    __target_switch\n")
14328
0
SLANG_RAW("    {\n")
14329
0
SLANG_RAW("    case glsl: __intrinsic_asm \"radians\";\n")
14330
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"radians\";\n")
14331
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14332
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Radians $x\n")
14333
0
SLANG_RAW("    };\n")
14334
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"radians\";\n")
14335
0
SLANG_RAW("    default:\n")
14336
0
SLANG_RAW("        return x * (T.getPi() / T(180.0f));\n")
14337
0
SLANG_RAW("    }\n")
14338
0
SLANG_RAW("}\n")
14339
0
SLANG_RAW("\n")
14340
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14341
0
SLANG_RAW("[__readNone]\n")
14342
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14343
0
SLANG_RAW("matrix<T, N, M> radians(matrix<T, N, M> x)\n")
14344
0
SLANG_RAW("{\n")
14345
0
SLANG_RAW("    __target_switch\n")
14346
0
SLANG_RAW("    {\n")
14347
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"radians\";\n")
14348
0
SLANG_RAW("    default:\n")
14349
0
SLANG_RAW("        return x * (T.getPi() / T(180.0f));\n")
14350
0
SLANG_RAW("    }\n")
14351
0
SLANG_RAW("}\n")
14352
0
SLANG_RAW("\n")
14353
0
SLANG_RAW("/// Compute approximate reciprocal of `x`.\n")
14354
0
SLANG_RAW("/// @param x The value to compute the reciprocal of.\n")
14355
0
SLANG_RAW("/// @return The approximate reciprocal of `x`.\n")
14356
0
SLANG_RAW("/// @category math\n")
14357
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14358
0
SLANG_RAW("[__readNone]\n")
14359
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14360
0
SLANG_RAW("T rcp(T x)\n")
14361
0
SLANG_RAW("{\n")
14362
0
SLANG_RAW("    __target_switch\n")
14363
0
SLANG_RAW("    {\n")
14364
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rcp\";\n")
14365
0
SLANG_RAW("    default:\n")
14366
0
SLANG_RAW("        return T(1.0) / x;\n")
14367
0
SLANG_RAW("    }\n")
14368
0
SLANG_RAW("}\n")
14369
0
SLANG_RAW("\n")
14370
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14371
0
SLANG_RAW("[__readNone]\n")
14372
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14373
0
SLANG_RAW("vector<T, N> rcp(vector<T, N> x)\n")
14374
0
SLANG_RAW("{\n")
14375
0
SLANG_RAW("    __target_switch\n")
14376
0
SLANG_RAW("    {\n")
14377
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rcp\";\n")
14378
0
SLANG_RAW("    case glsl:\n")
14379
0
SLANG_RAW("    case spirv:\n")
14380
0
SLANG_RAW("    case wgsl:\n")
14381
0
SLANG_RAW("        return T(1.0) / x;\n")
14382
0
SLANG_RAW("    default:\n")
14383
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, rcp, x);\n")
14384
0
SLANG_RAW("    }\n")
14385
0
SLANG_RAW("}\n")
14386
0
SLANG_RAW("\n")
14387
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14388
0
SLANG_RAW("[__readNone]\n")
14389
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14390
0
SLANG_RAW("matrix<T, N, M> rcp(matrix<T, N, M> x)\n")
14391
0
SLANG_RAW("{\n")
14392
0
SLANG_RAW("    __target_switch\n")
14393
0
SLANG_RAW("    {\n")
14394
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rcp\";\n")
14395
0
SLANG_RAW("    default:\n")
14396
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, rcp, x);\n")
14397
0
SLANG_RAW("    }\n")
14398
0
SLANG_RAW("}\n")
14399
0
SLANG_RAW("\n")
14400
0
SLANG_RAW("/// Reflect incident vector across plane with given normal.\n")
14401
0
SLANG_RAW("/// @param i The incident vector.\n")
14402
0
SLANG_RAW("/// @param n The normal vector.\n")
14403
0
SLANG_RAW("/// @return The reflected vector.\n")
14404
0
SLANG_RAW("/// @category math\n")
14405
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14406
0
SLANG_RAW("[__readNone]\n")
14407
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14408
0
SLANG_RAW("T reflect(T i, T n)\n")
14409
0
SLANG_RAW("{\n")
14410
0
SLANG_RAW("    __target_switch\n")
14411
0
SLANG_RAW("    {\n")
14412
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reflect\";\n")
14413
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"reflect\";\n")
14414
0
SLANG_RAW("    case metal: __intrinsic_asm \"reflect\";\n")
14415
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14416
0
SLANG_RAW("        OpExtInst $$T result glsl450 Reflect $i $n\n")
14417
0
SLANG_RAW("    };\n")
14418
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"reflect\";\n")
14419
0
SLANG_RAW("    default:\n")
14420
0
SLANG_RAW("        return i - T(2) * dot(n,i) * n;\n")
14421
0
SLANG_RAW("    }\n")
14422
0
SLANG_RAW("}\n")
14423
0
SLANG_RAW("\n")
14424
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14425
0
SLANG_RAW("[__readNone]\n")
14426
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14427
0
SLANG_RAW("vector<T,N> reflect(vector<T,N> i, vector<T,N> n)\n")
14428
0
SLANG_RAW("{\n")
14429
0
SLANG_RAW("    __target_switch\n")
14430
0
SLANG_RAW("    {\n")
14431
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reflect\";\n")
14432
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"reflect\";\n")
14433
0
SLANG_RAW("    case metal: __intrinsic_asm \"reflect\";\n")
14434
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14435
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Reflect $i $n\n")
14436
0
SLANG_RAW("    };\n")
14437
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"reflect\";\n")
14438
0
SLANG_RAW("    default:\n")
14439
0
SLANG_RAW("        return i - T(2) * dot(n,i) * n;\n")
14440
0
SLANG_RAW("    }\n")
14441
0
SLANG_RAW("}\n")
14442
0
SLANG_RAW("\n")
14443
0
SLANG_RAW("/// Refract incident vector given surface normal and index of refraction.\n")
14444
0
SLANG_RAW("/// @param i The incident vector.\n")
14445
0
SLANG_RAW("/// @param n The normal vector.\n")
14446
0
SLANG_RAW("/// @param eta The relative refractive index.\n")
14447
0
SLANG_RAW("/// @category math\n")
14448
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14449
0
SLANG_RAW("[__readNone]\n")
14450
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14451
0
SLANG_RAW("vector<T,N> refract(vector<T,N> i, vector<T,N> n, T eta)\n")
14452
0
SLANG_RAW("{\n")
14453
0
SLANG_RAW("    __target_switch\n")
14454
0
SLANG_RAW("    {\n")
14455
0
SLANG_RAW("    case glsl: __intrinsic_asm \"refract\";\n")
14456
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"refract\";\n")
14457
0
SLANG_RAW("    case metal: __intrinsic_asm \"refract\";\n")
14458
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14459
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Refract $i $n $eta\n")
14460
0
SLANG_RAW("    };\n")
14461
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"refract\";\n")
14462
0
SLANG_RAW("    default:\n")
14463
0
SLANG_RAW("        let dotNI = dot(n,i);\n")
14464
0
SLANG_RAW("        let k = T(1) - eta*eta*(T(1) - dotNI * dotNI);\n")
14465
0
SLANG_RAW("        if(k < T(0)) return vector<T,N>(T(0));\n")
14466
0
SLANG_RAW("        return eta * i - (eta * dotNI + sqrt(k)) * n;\n")
14467
0
SLANG_RAW("    }\n")
14468
0
SLANG_RAW("}\n")
14469
0
SLANG_RAW("\n")
14470
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14471
0
SLANG_RAW("[__readNone]\n")
14472
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14473
0
SLANG_RAW("T refract(T i, T n, T eta)\n")
14474
0
SLANG_RAW("{\n")
14475
0
SLANG_RAW("    __target_switch\n")
14476
0
SLANG_RAW("    {\n")
14477
0
SLANG_RAW("    case glsl: __intrinsic_asm \"refract\";\n")
14478
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"refract\";\n")
14479
0
SLANG_RAW("    case metal: __intrinsic_asm \"refract\";\n")
14480
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14481
0
SLANG_RAW("        OpExtInst $$T result glsl450 Refract $i $n $eta\n")
14482
0
SLANG_RAW("    };\n")
14483
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"refract\";\n")
14484
0
SLANG_RAW("    default:\n")
14485
0
SLANG_RAW("        let dotNI = dot(n,i);\n")
14486
0
SLANG_RAW("        let k = T(1) - eta*eta*(T(1) - dotNI * dotNI);\n")
14487
0
SLANG_RAW("        if(k < T(0)) return T(0);\n")
14488
0
SLANG_RAW("        return eta * i - (eta * dotNI + sqrt(k)) * n;\n")
14489
0
SLANG_RAW("    }\n")
14490
0
SLANG_RAW("}\n")
14491
0
SLANG_RAW("\n")
14492
0
SLANG_RAW("/// Reverse order of bits.\n")
14493
0
SLANG_RAW("/// @param value The value to reverse bits of.\n")
14494
0
SLANG_RAW("/// @return The bits of `value`, reversed such that bit n of the result is equal to bit (width - 1 - n) of `value`.\n")
14495
0
SLANG_RAW("/// @remarks For SPIR-V, this function maps to `OpBitReverse`.\n")
14496
0
SLANG_RAW("/// @category bitops\n")
14497
0
SLANG_RAW("[__readNone]\n")
14498
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
14499
0
SLANG_RAW("uint reversebits(uint value)\n")
14500
0
SLANG_RAW("{\n")
14501
0
SLANG_RAW("    __target_switch\n")
14502
0
SLANG_RAW("    {\n")
14503
0
SLANG_RAW("    case hlsl:\n")
14504
0
SLANG_RAW("        __intrinsic_asm \"reversebits\";\n")
14505
0
SLANG_RAW("    case glsl:\n")
14506
0
SLANG_RAW("        __intrinsic_asm \"bitfieldReverse\";\n")
14507
0
SLANG_RAW("    case cuda:\n")
14508
0
SLANG_RAW("    case cpp:\n")
14509
0
SLANG_RAW("        __intrinsic_asm \"$P_reversebits($0)\";\n")
14510
0
SLANG_RAW("    case metal:\n")
14511
0
SLANG_RAW("        __intrinsic_asm \"reverse_bits\";\n")
14512
0
SLANG_RAW("    case spirv:\n")
14513
0
SLANG_RAW("        return spirv_asm {OpBitReverse $$uint result $value};\n")
14514
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"reverseBits\";\n")
14515
0
SLANG_RAW("    }\n")
14516
0
SLANG_RAW("}\n")
14517
0
SLANG_RAW("\n")
14518
0
SLANG_RAW("__generic<let N : int>\n")
14519
0
SLANG_RAW("[__readNone]\n")
14520
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)]\n")
14521
0
SLANG_RAW("vector<uint, N> reversebits(vector<uint, N> value)\n")
14522
0
SLANG_RAW("{\n")
14523
0
SLANG_RAW("    __target_switch\n")
14524
0
SLANG_RAW("    {\n")
14525
0
SLANG_RAW("    default:\n")
14526
0
SLANG_RAW("        VECTOR_MAP_UNARY(uint, N, reversebits, value);\n")
14527
0
SLANG_RAW("    case glsl:\n")
14528
0
SLANG_RAW("        __intrinsic_asm \"bitfieldReverse\";\n")
14529
0
SLANG_RAW("    case metal:\n")
14530
0
SLANG_RAW("        __intrinsic_asm \"reverse_bits\";\n")
14531
0
SLANG_RAW("    case spirv:\n")
14532
0
SLANG_RAW("        return spirv_asm {OpBitReverse $$vector<uint, N> result $value};\n")
14533
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"reverseBits\";\n")
14534
0
SLANG_RAW("    }\n")
14535
0
SLANG_RAW("}\n")
14536
0
SLANG_RAW("\n")
14537
0
SLANG_RAW("/// Round even.\n")
14538
0
SLANG_RAW("/// @param x The value to round.\n")
14539
0
SLANG_RAW("/// @return The value rounded to the nearest integer, with ties rounded to the nearest even integer.\n")
14540
0
SLANG_RAW("/// @category math\n")
14541
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14542
0
SLANG_RAW("[__readNone]\n")
14543
0
SLANG_RAW("[ForceInline]\n")
14544
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
14545
0
SLANG_RAW("T rint(T x)\n")
14546
0
SLANG_RAW("{\n")
14547
0
SLANG_RAW("    __target_switch\n")
14548
0
SLANG_RAW("    {\n")
14549
0
SLANG_RAW("    case glsl: __intrinsic_asm \"roundEven\";\n")
14550
0
SLANG_RAW("    case metal: __intrinsic_asm \"rint\";\n")
14551
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14552
0
SLANG_RAW("        OpExtInst $$T result glsl450 RoundEven $x\n")
14553
0
SLANG_RAW("    };\n")
14554
0
SLANG_RAW("    default:\n")
14555
0
SLANG_RAW("        T nearest = round(x);\n")
14556
0
SLANG_RAW("\n")
14557
0
SLANG_RAW("        // Check if the value is exactly halfway between two integers\n")
14558
0
SLANG_RAW("        if (abs(x - nearest) == T(0.5))\n")
14559
0
SLANG_RAW("        {\n")
14560
0
SLANG_RAW("            // If halfway, choose the even number\n")
14561
0
SLANG_RAW("            if ((nearest / T(2)) * T(2) != nearest)\n")
14562
0
SLANG_RAW("            {\n")
14563
0
SLANG_RAW("                // If the nearest number is odd,\n")
14564
0
SLANG_RAW("                // move to the closest even number\n")
14565
0
SLANG_RAW("                nearest -= ((x < nearest) ? T(1) : T(-1));\n")
14566
0
SLANG_RAW("            }\n")
14567
0
SLANG_RAW("        }\n")
14568
0
SLANG_RAW("        return nearest;\n")
14569
0
SLANG_RAW("    }\n")
14570
0
SLANG_RAW("}\n")
14571
0
SLANG_RAW("\n")
14572
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N:int>\n")
14573
0
SLANG_RAW("[__readNone]\n")
14574
0
SLANG_RAW("[ForceInline]\n")
14575
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, sm_4_0_version)]\n")
14576
0
SLANG_RAW("vector<T,N> rint(vector<T,N> x)\n")
14577
0
SLANG_RAW("{\n")
14578
0
SLANG_RAW("    __target_switch\n")
14579
0
SLANG_RAW("    {\n")
14580
0
SLANG_RAW("    case glsl: __intrinsic_asm \"roundEven\";\n")
14581
0
SLANG_RAW("    case metal: __intrinsic_asm \"rint\";\n")
14582
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14583
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 RoundEven $x\n")
14584
0
SLANG_RAW("    };\n")
14585
0
SLANG_RAW("    default:\n")
14586
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, rint, x);\n")
14587
0
SLANG_RAW("    }\n")
14588
0
SLANG_RAW("}\n")
14589
0
SLANG_RAW("\n")
14590
0
SLANG_RAW("/// Round-to-nearest.\n")
14591
0
SLANG_RAW("/// @param x The value to round.\n")
14592
0
SLANG_RAW("/// @return The value rounded to the nearest integer.\n")
14593
0
SLANG_RAW("/// @remarks Rounding behavior of .5 is determined by target intrinsic.\n")
14594
0
SLANG_RAW("/// @category math\n")
14595
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14596
0
SLANG_RAW("[__readNone]\n")
14597
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14598
0
SLANG_RAW("T round(T x)\n")
14599
0
SLANG_RAW("{\n")
14600
0
SLANG_RAW("    __target_switch\n")
14601
0
SLANG_RAW("    {\n")
14602
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_round($0)\";\n")
14603
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_round($0)\";\n")
14604
0
SLANG_RAW("    case glsl: __intrinsic_asm \"round\";\n")
14605
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"round\";\n")
14606
0
SLANG_RAW("    case metal: __intrinsic_asm \"round\";\n")
14607
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14608
0
SLANG_RAW("        OpExtInst $$T result glsl450 Round $x\n")
14609
0
SLANG_RAW("    };\n")
14610
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"round\";\n")
14611
0
SLANG_RAW("    }\n")
14612
0
SLANG_RAW("}\n")
14613
0
SLANG_RAW("\n")
14614
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14615
0
SLANG_RAW("[__readNone]\n")
14616
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14617
0
SLANG_RAW("vector<T, N> round(vector<T, N> x)\n")
14618
0
SLANG_RAW("{\n")
14619
0
SLANG_RAW("    __target_switch\n")
14620
0
SLANG_RAW("    {\n")
14621
0
SLANG_RAW("    case glsl: __intrinsic_asm \"round\";\n")
14622
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"round\";\n")
14623
0
SLANG_RAW("    case metal: __intrinsic_asm \"round\";\n")
14624
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14625
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Round $x\n")
14626
0
SLANG_RAW("    };\n")
14627
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"round\";\n")
14628
0
SLANG_RAW("    default:\n")
14629
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, round, x);\n")
14630
0
SLANG_RAW("    }\n")
14631
0
SLANG_RAW("}\n")
14632
0
SLANG_RAW("\n")
14633
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14634
0
SLANG_RAW("[__readNone]\n")
14635
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14636
0
SLANG_RAW("matrix<T,N,M> round(matrix<T,N,M> x)\n")
14637
0
SLANG_RAW("{\n")
14638
0
SLANG_RAW("    __target_switch\n")
14639
0
SLANG_RAW("    {\n")
14640
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"round\";\n")
14641
0
SLANG_RAW("    default:\n")
14642
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, round, x);\n")
14643
0
SLANG_RAW("    }\n")
14644
0
SLANG_RAW("}\n")
14645
0
SLANG_RAW("\n")
14646
0
SLANG_RAW("/// Reciprocal of square root.\n")
14647
0
SLANG_RAW("/// @param x The value to compute the reciprocal square root of.\n")
14648
0
SLANG_RAW("/// @return The reciprocal square root of `x`.\n")
14649
0
SLANG_RAW("/// @category math\n")
14650
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14651
0
SLANG_RAW("[__readNone]\n")
14652
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14653
0
SLANG_RAW("T rsqrt(T x)\n")
14654
0
SLANG_RAW("{\n")
14655
0
SLANG_RAW("    __target_switch\n")
14656
0
SLANG_RAW("    {\n")
14657
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_rsqrt($0)\";\n")
14658
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_rsqrt($0)\";\n")
14659
0
SLANG_RAW("    case glsl: __intrinsic_asm \"inversesqrt($0)\";\n")
14660
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rsqrt\";\n")
14661
0
SLANG_RAW("    case metal: __intrinsic_asm \"rsqrt\";\n")
14662
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14663
0
SLANG_RAW("        OpExtInst $$T result glsl450 InverseSqrt $x\n")
14664
0
SLANG_RAW("    };\n")
14665
0
SLANG_RAW("    default:\n")
14666
0
SLANG_RAW("        return T(1.0) / sqrt(x);\n")
14667
0
SLANG_RAW("    }\n")
14668
0
SLANG_RAW("}\n")
14669
0
SLANG_RAW("\n")
14670
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14671
0
SLANG_RAW("[__readNone]\n")
14672
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14673
0
SLANG_RAW("vector<T, N> rsqrt(vector<T, N> x)\n")
14674
0
SLANG_RAW("{\n")
14675
0
SLANG_RAW("    __target_switch\n")
14676
0
SLANG_RAW("    {\n")
14677
0
SLANG_RAW("    case glsl: __intrinsic_asm \"inversesqrt($0)\";\n")
14678
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rsqrt\";\n")
14679
0
SLANG_RAW("    case metal: __intrinsic_asm \"rsqrt\";\n")
14680
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14681
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 InverseSqrt $x\n")
14682
0
SLANG_RAW("    };\n")
14683
0
SLANG_RAW("    default:\n")
14684
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, rsqrt, x);\n")
14685
0
SLANG_RAW("    }\n")
14686
0
SLANG_RAW("}\n")
14687
0
SLANG_RAW("\n")
14688
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14689
0
SLANG_RAW("[__readNone]\n")
14690
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14691
0
SLANG_RAW("matrix<T, N, M> rsqrt(matrix<T, N, M> x)\n")
14692
0
SLANG_RAW("{\n")
14693
0
SLANG_RAW("    __target_switch\n")
14694
0
SLANG_RAW("    {\n")
14695
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"rsqrt\";\n")
14696
0
SLANG_RAW("    default:\n")
14697
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, rsqrt, x);\n")
14698
0
SLANG_RAW("    }\n")
14699
0
SLANG_RAW("}\n")
14700
0
SLANG_RAW("\n")
14701
0
SLANG_RAW("/// Clamp value to [0,1] range.\n")
14702
0
SLANG_RAW("/// @param x The value to clamp.\n")
14703
0
SLANG_RAW("/// @return The clamped value.\n")
14704
0
SLANG_RAW("/// @category math\n")
14705
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14706
0
SLANG_RAW("[__readNone]\n")
14707
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14708
0
SLANG_RAW("T saturate(T x)\n")
14709
0
SLANG_RAW("{\n")
14710
0
SLANG_RAW("    __target_switch\n")
14711
0
SLANG_RAW("    {\n")
14712
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"saturate\";\n")
14713
0
SLANG_RAW("    case metal: __intrinsic_asm \"saturate\";\n")
14714
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"saturate\";\n")
14715
0
SLANG_RAW("    default:\n")
14716
0
SLANG_RAW("        return clamp<T>(x, T(0), T(1));\n")
14717
0
SLANG_RAW("    }\n")
14718
0
SLANG_RAW("}\n")
14719
0
SLANG_RAW("\n")
14720
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14721
0
SLANG_RAW("[__readNone]\n")
14722
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14723
0
SLANG_RAW("vector<T,N> saturate(vector<T,N> x)\n")
14724
0
SLANG_RAW("{\n")
14725
0
SLANG_RAW("    __target_switch\n")
14726
0
SLANG_RAW("    {\n")
14727
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"saturate\";\n")
14728
0
SLANG_RAW("    case metal: __intrinsic_asm \"saturate\";\n")
14729
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"saturate\";\n")
14730
0
SLANG_RAW("    default:\n")
14731
0
SLANG_RAW("        return clamp<T,N>(x,\n")
14732
0
SLANG_RAW("            vector<T,N>(T(0)),\n")
14733
0
SLANG_RAW("            vector<T,N>(T(1)));\n")
14734
0
SLANG_RAW("    }\n")
14735
0
SLANG_RAW("}\n")
14736
0
SLANG_RAW("\n")
14737
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14738
0
SLANG_RAW("[__readNone]\n")
14739
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14740
0
SLANG_RAW("matrix<T,N,M> saturate(matrix<T,N,M> x)\n")
14741
0
SLANG_RAW("{\n")
14742
0
SLANG_RAW("    __target_switch\n")
14743
0
SLANG_RAW("    {\n")
14744
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"saturate\";\n")
14745
0
SLANG_RAW("    default:\n")
14746
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, saturate, x);\n")
14747
0
SLANG_RAW("    }\n")
14748
0
SLANG_RAW("}\n")
14749
0
SLANG_RAW("\n")
14750
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType>\n")
14751
0
SLANG_RAW("__intrinsic_op(")
14752
0
SLANG_SPLICE(kIROp_IntCast
14753
0
)
14754
0
SLANG_RAW(")\n")
14755
0
SLANG_RAW("T __int_cast(U val);\n")
14756
0
SLANG_RAW("\n")
14757
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType>\n")
14758
0
SLANG_RAW("__intrinsic_op(")
14759
0
SLANG_SPLICE(kIROp_FloatCast
14760
0
)
14761
0
SLANG_RAW(")\n")
14762
0
SLANG_RAW("T __real_cast(U val);\n")
14763
0
SLANG_RAW("\n")
14764
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType>\n")
14765
0
SLANG_RAW("__intrinsic_op(")
14766
0
SLANG_SPLICE(kIROp_CastIntToFloat
14767
0
)
14768
0
SLANG_RAW(")\n")
14769
0
SLANG_RAW("T __int_to_float_cast(U val);\n")
14770
0
SLANG_RAW("\n")
14771
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType>\n")
14772
0
SLANG_RAW("__intrinsic_op(")
14773
0
SLANG_SPLICE(kIROp_CastFloatToInt
14774
0
)
14775
0
SLANG_RAW(")\n")
14776
0
SLANG_RAW("T __float_to_int_cast(U val);\n")
14777
0
SLANG_RAW("\n")
14778
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType>\n")
14779
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
14780
0
SLANG_RAW("T __arithmetic_cast(U val)\n")
14781
0
SLANG_RAW("{\n")
14782
0
SLANG_RAW("    if (__isFloat<T>() && __isInt<U>())\n")
14783
0
SLANG_RAW("        return __int_to_float_cast<T>(val);\n")
14784
0
SLANG_RAW("    else if (__isInt<T>() && __isFloat<U>())\n")
14785
0
SLANG_RAW("        return __float_to_int_cast<T>(val);\n")
14786
0
SLANG_RAW("    else if (__isFloat<T>() && __isFloat<U>())\n")
14787
0
SLANG_RAW("        return __real_cast<T>(val);\n")
14788
0
SLANG_RAW("    else if (__isInt<T>() && __isInt<U>())\n")
14789
0
SLANG_RAW("        return __int_cast<T>(val);\n")
14790
0
SLANG_RAW("    return T(0);\n")
14791
0
SLANG_RAW("}\n")
14792
0
SLANG_RAW("\n")
14793
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
14794
0
SLANG_RAW("__intrinsic_op(")
14795
0
SLANG_SPLICE(kIROp_IntCast
14796
0
)
14797
0
SLANG_RAW(")\n")
14798
0
SLANG_RAW("vector<T,N> __int_cast(vector<U,N> val);\n")
14799
0
SLANG_RAW("\n")
14800
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
14801
0
SLANG_RAW("__intrinsic_op(")
14802
0
SLANG_SPLICE(kIROp_FloatCast
14803
0
)
14804
0
SLANG_RAW(")\n")
14805
0
SLANG_RAW("vector<T,N> __real_cast(vector<U,N> val);\n")
14806
0
SLANG_RAW("\n")
14807
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
14808
0
SLANG_RAW("__intrinsic_op(")
14809
0
SLANG_SPLICE(kIROp_CastIntToFloat
14810
0
)
14811
0
SLANG_RAW(")\n")
14812
0
SLANG_RAW("vector<T,N> __int_to_float_cast(vector<U,N> val);\n")
14813
0
SLANG_RAW("\n")
14814
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
14815
0
SLANG_RAW("__intrinsic_op(")
14816
0
SLANG_SPLICE(kIROp_CastFloatToInt
14817
0
)
14818
0
SLANG_RAW(")\n")
14819
0
SLANG_RAW("vector<T,N> __float_to_int_cast(vector<U,N> val);\n")
14820
0
SLANG_RAW("\n")
14821
0
SLANG_RAW("\n")
14822
0
SLANG_RAW("/// Extract sign of value.\n")
14823
0
SLANG_RAW("/// @param x The value to extract the sign of.\n")
14824
0
SLANG_RAW("/// @return -1 if `x` is negative, 0 if `x` is zero, and 1 if `x` is positive.\n")
14825
0
SLANG_RAW("/// @category math Math functions\n")
14826
0
SLANG_RAW("__generic<T : __BuiltinSignedArithmeticType>\n")
14827
0
SLANG_RAW("[__readNone]\n")
14828
0
SLANG_RAW("int sign(T x)\n")
14829
0
SLANG_RAW("{\n")
14830
0
SLANG_RAW("    __target_switch\n")
14831
0
SLANG_RAW("    {\n")
14832
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sign\";\n")
14833
0
SLANG_RAW("    case metal: __intrinsic_asm \"int(sign($0))\";\n")
14834
0
SLANG_RAW("    case glsl: __intrinsic_asm \"int(sign($0))\";\n")
14835
0
SLANG_RAW("    case cuda:\n")
14836
0
SLANG_RAW("    case cpp:\n")
14837
0
SLANG_RAW("        __intrinsic_asm \"$P_sign($0)\";\n")
14838
0
SLANG_RAW("    case spirv:\n")
14839
0
SLANG_RAW("        if (__isFloat<T>())\n")
14840
0
SLANG_RAW("            return spirv_asm\n")
14841
0
SLANG_RAW("            {\n")
14842
0
SLANG_RAW("                %fsign:$$T = OpExtInst glsl450 FSign $x;\n")
14843
0
SLANG_RAW("                result:$$int = OpConvertFToS %fsign\n")
14844
0
SLANG_RAW("            };\n")
14845
0
SLANG_RAW("        else\n")
14846
0
SLANG_RAW("            return __int_cast<int>(spirv_asm {OpExtInst $$T result glsl450 SSign $x});\n")
14847
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"i32(sign($0))\";\n")
14848
0
SLANG_RAW("    }\n")
14849
0
SLANG_RAW("}\n")
14850
0
SLANG_RAW("\n")
14851
0
SLANG_RAW("__generic<T : __BuiltinSignedArithmeticType, let N : int>\n")
14852
0
SLANG_RAW("[__readNone]\n")
14853
0
SLANG_RAW("vector<int, N> sign(vector<T, N> x)\n")
14854
0
SLANG_RAW("{\n")
14855
0
SLANG_RAW("    if(N == 1)\n")
14856
0
SLANG_RAW("        return vector<int, N>(sign(x[0]));\n")
14857
0
SLANG_RAW("    __target_switch\n")
14858
0
SLANG_RAW("    {\n")
14859
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sign\";\n")
14860
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ivec$N0(sign($0))\";\n")
14861
0
SLANG_RAW("    case metal: __intrinsic_asm \"vec<int,$N0>(sign($0))\";\n")
14862
0
SLANG_RAW("    case spirv:\n")
14863
0
SLANG_RAW("        if (__isFloat<T>())\n")
14864
0
SLANG_RAW("            return spirv_asm\n")
14865
0
SLANG_RAW("            {\n")
14866
0
SLANG_RAW("                %fsign:$$vector<T, N> = OpExtInst glsl450 FSign $x;\n")
14867
0
SLANG_RAW("                result:$$vector<int, N> = OpConvertFToS %fsign\n")
14868
0
SLANG_RAW("            };\n")
14869
0
SLANG_RAW("        else\n")
14870
0
SLANG_RAW("            return __int_cast<int>(spirv_asm {OpExtInst $$vector<T,N> result glsl450 SSign $x});\n")
14871
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"vec$N0<i32>(sign($0))\";\n")
14872
0
SLANG_RAW("    default:\n")
14873
0
SLANG_RAW("        VECTOR_MAP_UNARY(int, N, sign, x);\n")
14874
0
SLANG_RAW("    }\n")
14875
0
SLANG_RAW("}\n")
14876
0
SLANG_RAW("\n")
14877
0
SLANG_RAW("__generic<T : __BuiltinSignedArithmeticType, let N : int, let M : int>\n")
14878
0
SLANG_RAW("[__readNone]\n")
14879
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)]\n")
14880
0
SLANG_RAW("matrix<int, N, M> sign(matrix<T, N, M> x)\n")
14881
0
SLANG_RAW("{\n")
14882
0
SLANG_RAW("    __target_switch\n")
14883
0
SLANG_RAW("    {\n")
14884
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sign\";\n")
14885
0
SLANG_RAW("    default:\n")
14886
0
SLANG_RAW("        MATRIX_MAP_UNARY(int, N, M, sign, x);\n")
14887
0
SLANG_RAW("    }\n")
14888
0
SLANG_RAW("}\n")
14889
0
SLANG_RAW("\n")
14890
0
SLANG_RAW("/// Sine.\n")
14891
0
SLANG_RAW("/// @param x The angle in radians.\n")
14892
0
SLANG_RAW("/// @return The sine of `x`.\n")
14893
0
SLANG_RAW("/// @category math\n")
14894
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14895
0
SLANG_RAW("[__readNone]\n")
14896
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14897
0
SLANG_RAW("T sin(T x)\n")
14898
0
SLANG_RAW("{\n")
14899
0
SLANG_RAW("    __target_switch\n")
14900
0
SLANG_RAW("    {\n")
14901
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_sin($0)\";\n")
14902
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_sin($0)\";\n")
14903
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sin\";\n")
14904
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sin\";\n")
14905
0
SLANG_RAW("    case metal: __intrinsic_asm \"sin\";\n")
14906
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14907
0
SLANG_RAW("        OpExtInst $$T result glsl450 Sin $x\n")
14908
0
SLANG_RAW("    };\n")
14909
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sin\";\n")
14910
0
SLANG_RAW("    }\n")
14911
0
SLANG_RAW("}\n")
14912
0
SLANG_RAW("\n")
14913
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14914
0
SLANG_RAW("[__readNone]\n")
14915
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14916
0
SLANG_RAW("vector<T, N> sin(vector<T, N> x)\n")
14917
0
SLANG_RAW("{\n")
14918
0
SLANG_RAW("    __target_switch\n")
14919
0
SLANG_RAW("    {\n")
14920
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sin\";\n")
14921
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sin\";\n")
14922
0
SLANG_RAW("    case metal: __intrinsic_asm \"sin\";\n")
14923
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
14924
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Sin $x\n")
14925
0
SLANG_RAW("    };\n")
14926
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sin\";\n")
14927
0
SLANG_RAW("    default:\n")
14928
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, sin, x);\n")
14929
0
SLANG_RAW("    }\n")
14930
0
SLANG_RAW("}\n")
14931
0
SLANG_RAW("\n")
14932
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
14933
0
SLANG_RAW("[__readNone]\n")
14934
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14935
0
SLANG_RAW("matrix<T, N, M> sin(matrix<T, N, M> x)\n")
14936
0
SLANG_RAW("{\n")
14937
0
SLANG_RAW("    __target_switch\n")
14938
0
SLANG_RAW("    {\n")
14939
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sin\";\n")
14940
0
SLANG_RAW("    default:\n")
14941
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, sin, x);\n")
14942
0
SLANG_RAW("    }\n")
14943
0
SLANG_RAW("}\n")
14944
0
SLANG_RAW("\n")
14945
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14946
0
SLANG_RAW("[__readNone]\n")
14947
0
SLANG_RAW("[require(metal)]\n")
14948
0
SLANG_RAW("T __sincos_metal(T x, out T c)\n")
14949
0
SLANG_RAW("{\n")
14950
0
SLANG_RAW("    __target_switch\n")
14951
0
SLANG_RAW("    {\n")
14952
0
SLANG_RAW("    case metal: __intrinsic_asm \"sincos($0, *$1)\";\n")
14953
0
SLANG_RAW("    }\n")
14954
0
SLANG_RAW("}\n")
14955
0
SLANG_RAW("\n")
14956
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14957
0
SLANG_RAW("[__readNone]\n")
14958
0
SLANG_RAW("[require(metal)]\n")
14959
0
SLANG_RAW("vector<T,N> __sincos_metal(vector<T,N> x, out vector<T,N> c)\n")
14960
0
SLANG_RAW("{\n")
14961
0
SLANG_RAW("    __target_switch\n")
14962
0
SLANG_RAW("    {\n")
14963
0
SLANG_RAW("    case metal: __intrinsic_asm \"sincos($0, *$1)\";\n")
14964
0
SLANG_RAW("    }\n")
14965
0
SLANG_RAW("}\n")
14966
0
SLANG_RAW("\n")
14967
0
SLANG_RAW("/// Sine and cosine.\n")
14968
0
SLANG_RAW("/// Calculate both the sine and cosine of `x`.\n")
14969
0
SLANG_RAW("/// @param x The angle in radians.\n")
14970
0
SLANG_RAW("/// @param[out] s The sine of `x`.\n")
14971
0
SLANG_RAW("/// @param[out] c The cosine of `x`.\n")
14972
0
SLANG_RAW("/// @return void\n")
14973
0
SLANG_RAW("/// @category math\n")
14974
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
14975
0
SLANG_RAW("[__readNone]\n")
14976
0
SLANG_RAW("[ForceInline]\n")
14977
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14978
0
SLANG_RAW("void sincos(T x, out T s, out T c)\n")
14979
0
SLANG_RAW("{\n")
14980
0
SLANG_RAW("    __target_switch\n")
14981
0
SLANG_RAW("    {\n")
14982
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_sincos($0, $1, $2)\";\n")
14983
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sincos\";\n")
14984
0
SLANG_RAW("    case metal:\n")
14985
0
SLANG_RAW("        //__intrinsic_asm \"*($1) = sincos($0, *($2))\";\n")
14986
0
SLANG_RAW("        s = __sincos_metal(x, c);\n")
14987
0
SLANG_RAW("        return;\n")
14988
0
SLANG_RAW("    default:\n")
14989
0
SLANG_RAW("        s = sin(x);\n")
14990
0
SLANG_RAW("        c = cos(x);\n")
14991
0
SLANG_RAW("    }\n")
14992
0
SLANG_RAW("}\n")
14993
0
SLANG_RAW("\n")
14994
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
14995
0
SLANG_RAW("[__readNone]\n")
14996
0
SLANG_RAW("[ForceInline]\n")
14997
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
14998
0
SLANG_RAW("void sincos(vector<T,N> x, out vector<T,N> s, out vector<T,N> c)\n")
14999
0
SLANG_RAW("{\n")
15000
0
SLANG_RAW("    __target_switch\n")
15001
0
SLANG_RAW("    {\n")
15002
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sincos\";\n")
15003
0
SLANG_RAW("    case metal:\n")
15004
0
SLANG_RAW("        //__intrinsic_asm \"*($1) = sincos($0, *($2))\";\n")
15005
0
SLANG_RAW("        s = __sincos_metal(x, c);\n")
15006
0
SLANG_RAW("        return;\n")
15007
0
SLANG_RAW("    default:\n")
15008
0
SLANG_RAW("        s = sin(x);\n")
15009
0
SLANG_RAW("        c = cos(x);\n")
15010
0
SLANG_RAW("    }\n")
15011
0
SLANG_RAW("}\n")
15012
0
SLANG_RAW("\n")
15013
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L1: int, let L2 : int>\n")
15014
0
SLANG_RAW("[__readNone]\n")
15015
0
SLANG_RAW("[ForceInline]\n")
15016
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15017
0
SLANG_RAW("void sincos(matrix<T,N,M> x, out matrix<T,N,M,L1> s, out matrix<T,N,M,L2> c)\n")
15018
0
SLANG_RAW("{\n")
15019
0
SLANG_RAW("    __target_switch\n")
15020
0
SLANG_RAW("    {\n")
15021
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sincos\";\n")
15022
0
SLANG_RAW("    default:\n")
15023
0
SLANG_RAW("        s = sin(x);\n")
15024
0
SLANG_RAW("        c = cos(x);\n")
15025
0
SLANG_RAW("    }\n")
15026
0
SLANG_RAW("}\n")
15027
0
SLANG_RAW("\n")
15028
0
SLANG_RAW("/// Hyperbolic sine.\n")
15029
0
SLANG_RAW("/// @param x The value to compute the hyperbolic sine of.\n")
15030
0
SLANG_RAW("/// @return The hyperbolic sine of `x`.\n")
15031
0
SLANG_RAW("/// @category math\n")
15032
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15033
0
SLANG_RAW("[__readNone]\n")
15034
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15035
0
SLANG_RAW("T sinh(T x)\n")
15036
0
SLANG_RAW("{\n")
15037
0
SLANG_RAW("    __target_switch\n")
15038
0
SLANG_RAW("    {\n")
15039
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_sinh($0)\";\n")
15040
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_sinh($0)\";\n")
15041
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sinh\";\n")
15042
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sinh\";\n")
15043
0
SLANG_RAW("    case metal: __intrinsic_asm \"sinh\";\n")
15044
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15045
0
SLANG_RAW("        OpExtInst $$T result glsl450 Sinh $x\n")
15046
0
SLANG_RAW("    };\n")
15047
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sinh\";\n")
15048
0
SLANG_RAW("    }\n")
15049
0
SLANG_RAW("}\n")
15050
0
SLANG_RAW("\n")
15051
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15052
0
SLANG_RAW("[__readNone]\n")
15053
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15054
0
SLANG_RAW("vector<T, N> sinh(vector<T, N> x)\n")
15055
0
SLANG_RAW("{\n")
15056
0
SLANG_RAW("    __target_switch\n")
15057
0
SLANG_RAW("    {\n")
15058
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sinh\";\n")
15059
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sinh\";\n")
15060
0
SLANG_RAW("    case metal: __intrinsic_asm \"sinh\";\n")
15061
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15062
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Sinh $x\n")
15063
0
SLANG_RAW("    };\n")
15064
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sinh\";\n")
15065
0
SLANG_RAW("    default:\n")
15066
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, sinh, x);\n")
15067
0
SLANG_RAW("    }\n")
15068
0
SLANG_RAW("}\n")
15069
0
SLANG_RAW("\n")
15070
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15071
0
SLANG_RAW("[__readNone]\n")
15072
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15073
0
SLANG_RAW("matrix<T, N, M> sinh(matrix<T, N, M> x)\n")
15074
0
SLANG_RAW("{\n")
15075
0
SLANG_RAW("    __target_switch\n")
15076
0
SLANG_RAW("    {\n")
15077
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sinh\";\n")
15078
0
SLANG_RAW("    default:\n")
15079
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, sinh, x);\n")
15080
0
SLANG_RAW("    }\n")
15081
0
SLANG_RAW("}\n")
15082
0
SLANG_RAW("\n")
15083
0
SLANG_RAW("/// Compute the sine of `x * pi`.\n")
15084
0
SLANG_RAW("/// @param x The value to compute the sine of.\n")
15085
0
SLANG_RAW("/// @return The sine of `x * pi`.\n")
15086
0
SLANG_RAW("/// @category math\n")
15087
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15088
0
SLANG_RAW("[__readNone]\n")
15089
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15090
0
SLANG_RAW("T sinpi(T x)\n")
15091
0
SLANG_RAW("{\n")
15092
0
SLANG_RAW("    __target_switch\n")
15093
0
SLANG_RAW("    {\n")
15094
0
SLANG_RAW("    case metal: __intrinsic_asm \"sinpi\";\n")
15095
0
SLANG_RAW("    default:\n")
15096
0
SLANG_RAW("        return sin(T.getPi() * x);\n")
15097
0
SLANG_RAW("    }\n")
15098
0
SLANG_RAW("}\n")
15099
0
SLANG_RAW("\n")
15100
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15101
0
SLANG_RAW("[__readNone]\n")
15102
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15103
0
SLANG_RAW("vector<T,N> sinpi(vector<T,N> x)\n")
15104
0
SLANG_RAW("{\n")
15105
0
SLANG_RAW("    __target_switch\n")
15106
0
SLANG_RAW("    {\n")
15107
0
SLANG_RAW("    case metal: __intrinsic_asm \"sinpi\";\n")
15108
0
SLANG_RAW("    default:\n")
15109
0
SLANG_RAW("        return sin(T.getPi() * x);\n")
15110
0
SLANG_RAW("    }\n")
15111
0
SLANG_RAW("}\n")
15112
0
SLANG_RAW("\n")
15113
0
SLANG_RAW("\n")
15114
0
SLANG_RAW("/// Smooth step (Hermite interpolation).\n")
15115
0
SLANG_RAW("/// @param min The lower edge of the interpolation range.\n")
15116
0
SLANG_RAW("/// @param max The upper edge of the interpolation range.\n")
15117
0
SLANG_RAW("/// @param x The value to interpolate.\n")
15118
0
SLANG_RAW("/// @return 0 if `x` is less than `min`, 1 if `x` is greater than `max`, and a smooth interpolation between 0 and 1 otherwise.\n")
15119
0
SLANG_RAW("/// @category math\n")
15120
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15121
0
SLANG_RAW("[__readNone]\n")
15122
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15123
0
SLANG_RAW("T smoothstep(T min, T max, T x)\n")
15124
0
SLANG_RAW("{\n")
15125
0
SLANG_RAW("    __target_switch\n")
15126
0
SLANG_RAW("    {\n")
15127
0
SLANG_RAW("    case glsl: __intrinsic_asm \"smoothstep\";\n")
15128
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"smoothstep\";\n")
15129
0
SLANG_RAW("    case metal: __intrinsic_asm \"smoothstep\";\n")
15130
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15131
0
SLANG_RAW("        OpExtInst $$T result glsl450 SmoothStep $min $max $x\n")
15132
0
SLANG_RAW("    };\n")
15133
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"smoothstep\";\n")
15134
0
SLANG_RAW("    default:\n")
15135
0
SLANG_RAW("        let t = saturate((x - min) / (max - min));\n")
15136
0
SLANG_RAW("        return t * t * (T(3.0f) - (t + t));\n")
15137
0
SLANG_RAW("    }\n")
15138
0
SLANG_RAW("}\n")
15139
0
SLANG_RAW("\n")
15140
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15141
0
SLANG_RAW("[__readNone]\n")
15142
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15143
0
SLANG_RAW("vector<T, N> smoothstep(vector<T, N> min, vector<T, N> max, vector<T, N> x)\n")
15144
0
SLANG_RAW("{\n")
15145
0
SLANG_RAW("    __target_switch\n")
15146
0
SLANG_RAW("    {\n")
15147
0
SLANG_RAW("    case glsl: __intrinsic_asm \"smoothstep\";\n")
15148
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"smoothstep\";\n")
15149
0
SLANG_RAW("    case metal: __intrinsic_asm \"smoothstep\";\n")
15150
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15151
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 SmoothStep $min $max $x\n")
15152
0
SLANG_RAW("    };\n")
15153
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"smoothstep\";\n")
15154
0
SLANG_RAW("    default:\n")
15155
0
SLANG_RAW("        VECTOR_MAP_TRINARY(T, N, smoothstep, min, max, x);\n")
15156
0
SLANG_RAW("    }\n")
15157
0
SLANG_RAW("}\n")
15158
0
SLANG_RAW("\n")
15159
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15160
0
SLANG_RAW("[__readNone]\n")
15161
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15162
0
SLANG_RAW("matrix<T, N, M> smoothstep(matrix<T, N, M> min, matrix<T, N, M> max, matrix<T, N, M> x)\n")
15163
0
SLANG_RAW("{\n")
15164
0
SLANG_RAW("    __target_switch\n")
15165
0
SLANG_RAW("    {\n")
15166
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"smoothstep\";\n")
15167
0
SLANG_RAW("    default:\n")
15168
0
SLANG_RAW("        MATRIX_MAP_TRINARY(T, N, M, smoothstep, min, max, x);\n")
15169
0
SLANG_RAW("    }\n")
15170
0
SLANG_RAW("}\n")
15171
0
SLANG_RAW("\n")
15172
0
SLANG_RAW("/// Compute the square root of `x`.\n")
15173
0
SLANG_RAW("/// @param x The value to compute the square root of.\n")
15174
0
SLANG_RAW("/// @return The square root of `x`.\n")
15175
0
SLANG_RAW("/// @category math\n")
15176
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15177
0
SLANG_RAW("[__readNone]\n")
15178
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15179
0
SLANG_RAW("T sqrt(T x)\n")
15180
0
SLANG_RAW("{\n")
15181
0
SLANG_RAW("    __target_switch\n")
15182
0
SLANG_RAW("    {\n")
15183
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_sqrt($0)\";\n")
15184
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_sqrt($0)\";\n")
15185
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sqrt\";\n")
15186
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sqrt\";\n")
15187
0
SLANG_RAW("    case metal: __intrinsic_asm \"sqrt\";\n")
15188
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15189
0
SLANG_RAW("        OpExtInst $$T result glsl450 Sqrt $x\n")
15190
0
SLANG_RAW("    };\n")
15191
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sqrt\";\n")
15192
0
SLANG_RAW("    }\n")
15193
0
SLANG_RAW("}\n")
15194
0
SLANG_RAW("\n")
15195
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15196
0
SLANG_RAW("[__readNone]\n")
15197
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15198
0
SLANG_RAW("vector<T, N> sqrt(vector<T, N> x)\n")
15199
0
SLANG_RAW("{\n")
15200
0
SLANG_RAW("    __target_switch\n")
15201
0
SLANG_RAW("    {\n")
15202
0
SLANG_RAW("    case glsl: __intrinsic_asm \"sqrt\";\n")
15203
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sqrt\";\n")
15204
0
SLANG_RAW("    case metal: __intrinsic_asm \"sqrt\";\n")
15205
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15206
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Sqrt $x\n")
15207
0
SLANG_RAW("    };\n")
15208
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"sqrt\";\n")
15209
0
SLANG_RAW("    default:\n")
15210
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, sqrt, x);\n")
15211
0
SLANG_RAW("    }\n")
15212
0
SLANG_RAW("}\n")
15213
0
SLANG_RAW("\n")
15214
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15215
0
SLANG_RAW("[__readNone]\n")
15216
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15217
0
SLANG_RAW("matrix<T, N, M> sqrt(matrix<T, N, M> x)\n")
15218
0
SLANG_RAW("{\n")
15219
0
SLANG_RAW("    __target_switch\n")
15220
0
SLANG_RAW("    {\n")
15221
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"sqrt\";\n")
15222
0
SLANG_RAW("    default:\n")
15223
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, sqrt, x);\n")
15224
0
SLANG_RAW("    }\n")
15225
0
SLANG_RAW("}\n")
15226
0
SLANG_RAW("\n")
15227
0
SLANG_RAW("/// Step function.\n")
15228
0
SLANG_RAW("/// @param y The threshold value.\n")
15229
0
SLANG_RAW("/// @param x The value to compare against the threshold.\n")
15230
0
SLANG_RAW("/// @return 0 if `x` is less than `y`, and 1 otherwise.\n")
15231
0
SLANG_RAW("/// @category math\n")
15232
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15233
0
SLANG_RAW("[__readNone]\n")
15234
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15235
0
SLANG_RAW("T step(T y, T x)\n")
15236
0
SLANG_RAW("{\n")
15237
0
SLANG_RAW("    __target_switch\n")
15238
0
SLANG_RAW("    {\n")
15239
0
SLANG_RAW("    case glsl: __intrinsic_asm \"step\";\n")
15240
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"step\";\n")
15241
0
SLANG_RAW("    case metal: __intrinsic_asm \"step\";\n")
15242
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15243
0
SLANG_RAW("        OpExtInst $$T result glsl450 Step $y $x\n")
15244
0
SLANG_RAW("    };\n")
15245
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"step\";\n")
15246
0
SLANG_RAW("    default:\n")
15247
0
SLANG_RAW("        return x < y ? T(0.0f) : T(1.0f);\n")
15248
0
SLANG_RAW("    }\n")
15249
0
SLANG_RAW("}\n")
15250
0
SLANG_RAW("\n")
15251
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15252
0
SLANG_RAW("[__readNone]\n")
15253
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15254
0
SLANG_RAW("vector<T,N> step(vector<T,N> y, vector<T,N> x)\n")
15255
0
SLANG_RAW("{\n")
15256
0
SLANG_RAW("    __target_switch\n")
15257
0
SLANG_RAW("    {\n")
15258
0
SLANG_RAW("    case glsl: __intrinsic_asm \"step\";\n")
15259
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"step\";\n")
15260
0
SLANG_RAW("    case metal: __intrinsic_asm \"step\";\n")
15261
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15262
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Step $y $x\n")
15263
0
SLANG_RAW("    };\n")
15264
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"step\";\n")
15265
0
SLANG_RAW("    default:\n")
15266
0
SLANG_RAW("        VECTOR_MAP_BINARY(T, N, step, y, x);\n")
15267
0
SLANG_RAW("    }\n")
15268
0
SLANG_RAW("}\n")
15269
0
SLANG_RAW("\n")
15270
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15271
0
SLANG_RAW("[__readNone]\n")
15272
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15273
0
SLANG_RAW("matrix<T, N, M> step(matrix<T, N, M> y, matrix<T, N, M> x)\n")
15274
0
SLANG_RAW("{\n")
15275
0
SLANG_RAW("    __target_switch\n")
15276
0
SLANG_RAW("    {\n")
15277
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"step\";\n")
15278
0
SLANG_RAW("    default:\n")
15279
0
SLANG_RAW("        MATRIX_MAP_BINARY(T, N, M, step, y, x);\n")
15280
0
SLANG_RAW("    }\n")
15281
0
SLANG_RAW("}\n")
15282
0
SLANG_RAW("\n")
15283
0
SLANG_RAW("/// Compute the tangent of `x`.\n")
15284
0
SLANG_RAW("/// @param x The angle in radians.\n")
15285
0
SLANG_RAW("/// @return The tangent of `x`.\n")
15286
0
SLANG_RAW("/// @category math\n")
15287
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15288
0
SLANG_RAW("[__readNone]\n")
15289
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15290
0
SLANG_RAW("T tan(T x)\n")
15291
0
SLANG_RAW("{\n")
15292
0
SLANG_RAW("    __target_switch\n")
15293
0
SLANG_RAW("    {\n")
15294
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_tan($0)\";\n")
15295
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_tan($0)\";\n")
15296
0
SLANG_RAW("    case glsl: __intrinsic_asm \"tan\";\n")
15297
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tan\";\n")
15298
0
SLANG_RAW("    case metal: __intrinsic_asm \"tan\";\n")
15299
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15300
0
SLANG_RAW("        OpExtInst $$T result glsl450 Tan $x\n")
15301
0
SLANG_RAW("    };\n")
15302
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"tan\";\n")
15303
0
SLANG_RAW("    }\n")
15304
0
SLANG_RAW("}\n")
15305
0
SLANG_RAW("\n")
15306
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15307
0
SLANG_RAW("[__readNone]\n")
15308
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15309
0
SLANG_RAW("vector<T, N> tan(vector<T, N> x)\n")
15310
0
SLANG_RAW("{\n")
15311
0
SLANG_RAW("    __target_switch\n")
15312
0
SLANG_RAW("    {\n")
15313
0
SLANG_RAW("    case glsl: __intrinsic_asm \"tan\";\n")
15314
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tan\";\n")
15315
0
SLANG_RAW("    case metal: __intrinsic_asm \"tan\";\n")
15316
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15317
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Tan $x\n")
15318
0
SLANG_RAW("    };\n")
15319
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"tan\";\n")
15320
0
SLANG_RAW("    default:\n")
15321
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, tan, x);\n")
15322
0
SLANG_RAW("    }\n")
15323
0
SLANG_RAW("}\n")
15324
0
SLANG_RAW("\n")
15325
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15326
0
SLANG_RAW("[__readNone]\n")
15327
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15328
0
SLANG_RAW("matrix<T, N, M> tan(matrix<T, N, M> x)\n")
15329
0
SLANG_RAW("{\n")
15330
0
SLANG_RAW("    __target_switch\n")
15331
0
SLANG_RAW("    {\n")
15332
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tan\";\n")
15333
0
SLANG_RAW("    default:\n")
15334
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, tan, x);\n")
15335
0
SLANG_RAW("    }\n")
15336
0
SLANG_RAW("}\n")
15337
0
SLANG_RAW("\n")
15338
0
SLANG_RAW("/// Compute the hyperbolic tangent of `x`.\n")
15339
0
SLANG_RAW("/// @param x The value to compute the hyperbolic tangent of, in radians.\n")
15340
0
SLANG_RAW("/// @return The hyperbolic tangent of `x`.\n")
15341
0
SLANG_RAW("/// @category math\n")
15342
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15343
0
SLANG_RAW("[__readNone]\n")
15344
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15345
0
SLANG_RAW("T tanh(T x)\n")
15346
0
SLANG_RAW("{\n")
15347
0
SLANG_RAW("    __target_switch\n")
15348
0
SLANG_RAW("    {\n")
15349
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_tanh($0)\";\n")
15350
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_tanh($0)\";\n")
15351
0
SLANG_RAW("    case glsl: __intrinsic_asm \"tanh\";\n")
15352
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tanh\";\n")
15353
0
SLANG_RAW("    case metal: __intrinsic_asm \"tanh\";\n")
15354
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15355
0
SLANG_RAW("        OpExtInst $$T result glsl450 Tanh $x\n")
15356
0
SLANG_RAW("    };\n")
15357
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"tanh\";\n")
15358
0
SLANG_RAW("    }\n")
15359
0
SLANG_RAW("}\n")
15360
0
SLANG_RAW("\n")
15361
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15362
0
SLANG_RAW("[__readNone]\n")
15363
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15364
0
SLANG_RAW("vector<T,N> tanh(vector<T,N> x)\n")
15365
0
SLANG_RAW("{\n")
15366
0
SLANG_RAW("    __target_switch\n")
15367
0
SLANG_RAW("    {\n")
15368
0
SLANG_RAW("    case glsl: __intrinsic_asm \"tanh\";\n")
15369
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tanh\";\n")
15370
0
SLANG_RAW("    case metal: __intrinsic_asm \"tanh\";\n")
15371
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15372
0
SLANG_RAW("        OpExtInst $$vector<T,N> result glsl450 Tanh $x\n")
15373
0
SLANG_RAW("    };\n")
15374
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"tanh\";\n")
15375
0
SLANG_RAW("    default:\n")
15376
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, tanh, x);\n")
15377
0
SLANG_RAW("    }\n")
15378
0
SLANG_RAW("}\n")
15379
0
SLANG_RAW("\n")
15380
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15381
0
SLANG_RAW("[__readNone]\n")
15382
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15383
0
SLANG_RAW("matrix<T,N,M> tanh(matrix<T,N,M> x)\n")
15384
0
SLANG_RAW("{\n")
15385
0
SLANG_RAW("    __target_switch\n")
15386
0
SLANG_RAW("    {\n")
15387
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"tanh\";\n")
15388
0
SLANG_RAW("    default:\n")
15389
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, tanh, x);\n")
15390
0
SLANG_RAW("    }\n")
15391
0
SLANG_RAW("}\n")
15392
0
SLANG_RAW("\n")
15393
0
SLANG_RAW("/// Compute the tangent of `x * pi`.\n")
15394
0
SLANG_RAW("/// @param x The value to compute the tangent of.\n")
15395
0
SLANG_RAW("/// @return The tangent of `x * pi`.\n")
15396
0
SLANG_RAW("/// @category math\n")
15397
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15398
0
SLANG_RAW("[__readNone]\n")
15399
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15400
0
SLANG_RAW("T tanpi(T x)\n")
15401
0
SLANG_RAW("{\n")
15402
0
SLANG_RAW("    __target_switch\n")
15403
0
SLANG_RAW("    {\n")
15404
0
SLANG_RAW("    case metal: __intrinsic_asm \"tanpi\";\n")
15405
0
SLANG_RAW("    default:\n")
15406
0
SLANG_RAW("        return tan(T.getPi() * x);\n")
15407
0
SLANG_RAW("    }\n")
15408
0
SLANG_RAW("}\n")
15409
0
SLANG_RAW("\n")
15410
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15411
0
SLANG_RAW("[__readNone]\n")
15412
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15413
0
SLANG_RAW("vector<T,N> tanpi(vector<T,N> x)\n")
15414
0
SLANG_RAW("{\n")
15415
0
SLANG_RAW("    __target_switch\n")
15416
0
SLANG_RAW("    {\n")
15417
0
SLANG_RAW("    case metal: __intrinsic_asm \"tanpi\";\n")
15418
0
SLANG_RAW("    default:\n")
15419
0
SLANG_RAW("        return tan(T.getPi() * x);\n")
15420
0
SLANG_RAW("    }\n")
15421
0
SLANG_RAW("}\n")
15422
0
SLANG_RAW("\n")
15423
0
SLANG_RAW("\n")
15424
0
SLANG_RAW("/// Matrix transpose.\n")
15425
0
SLANG_RAW("/// @param x The matrix to transpose.\n")
15426
0
SLANG_RAW("/// @return The transposed matrix.\n")
15427
0
SLANG_RAW("/// @category math\n")
15428
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15429
0
SLANG_RAW("[__readNone]\n")
15430
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv_wgsl, sm_4_0_version)]\n")
15431
0
SLANG_RAW("[PreferRecompute]\n")
15432
0
SLANG_RAW("matrix<T, M, N> transpose(matrix<T, N, M> x)\n")
15433
0
SLANG_RAW("{\n")
15434
0
SLANG_RAW("    __target_switch\n")
15435
0
SLANG_RAW("    {\n")
15436
0
SLANG_RAW("    case glsl: __intrinsic_asm \"transpose\";\n")
15437
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"transpose\";\n")
15438
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15439
0
SLANG_RAW("        OpTranspose $$matrix<T, M, N> result $x\n")
15440
0
SLANG_RAW("    };\n")
15441
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"transpose\";\n")
15442
0
SLANG_RAW("    default:\n")
15443
0
SLANG_RAW("        matrix<T,M,N> result;\n")
15444
0
SLANG_RAW("        for(int r = 0; r < M; ++r)\n")
15445
0
SLANG_RAW("            for(int c = 0; c < N; ++c)\n")
15446
0
SLANG_RAW("                result[r][c] = x[c][r];\n")
15447
0
SLANG_RAW("        return result;\n")
15448
0
SLANG_RAW("    }\n")
15449
0
SLANG_RAW("}\n")
15450
0
SLANG_RAW("__generic<T : __BuiltinIntegerType, let N : int, let M : int>\n")
15451
0
SLANG_RAW("[__readNone]\n")
15452
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15453
0
SLANG_RAW("[PreferRecompute]\n")
15454
0
SLANG_RAW("matrix<T, M, N> transpose(matrix<T, N, M> x)\n")
15455
0
SLANG_RAW("{\n")
15456
0
SLANG_RAW("    __target_switch\n")
15457
0
SLANG_RAW("    {\n")
15458
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"transpose\";\n")
15459
0
SLANG_RAW("    // GLSL, WGSL, SPIR-V, and Metal don't support integer matrices when lowered, so transpose it manually\n")
15460
0
SLANG_RAW("    default:\n")
15461
0
SLANG_RAW("        matrix<T, M, N> result;\n")
15462
0
SLANG_RAW("        for (int r = 0; r < M; ++r)\n")
15463
0
SLANG_RAW("            for (int c = 0; c < N; ++c)\n")
15464
0
SLANG_RAW("                result[r][c] = x[c][r];\n")
15465
0
SLANG_RAW("        return result;\n")
15466
0
SLANG_RAW("    }\n")
15467
0
SLANG_RAW("}\n")
15468
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
15469
0
SLANG_RAW("[__readNone]\n")
15470
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15471
0
SLANG_RAW("[PreferRecompute]\n")
15472
0
SLANG_RAW("[OverloadRank(-1)]\n")
15473
0
SLANG_RAW("matrix<T, M, N> transpose(matrix<T, N, M> x)\n")
15474
0
SLANG_RAW("{\n")
15475
0
SLANG_RAW("    __target_switch\n")
15476
0
SLANG_RAW("    {\n")
15477
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"transpose\";\n")
15478
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15479
0
SLANG_RAW("        OpTranspose $$matrix<T, M, N> result $x\n")
15480
0
SLANG_RAW("    };\n")
15481
0
SLANG_RAW("    // GLSL, WGSL, and Metal don't support bool matrices when lowered, so transpose it manually\n")
15482
0
SLANG_RAW("    default:\n")
15483
0
SLANG_RAW("        matrix<T, M, N> result;\n")
15484
0
SLANG_RAW("        for (int r = 0; r < M; ++r)\n")
15485
0
SLANG_RAW("            for (int c = 0; c < N; ++c)\n")
15486
0
SLANG_RAW("                result[r][c] = x[c][r];\n")
15487
0
SLANG_RAW("        return result;\n")
15488
0
SLANG_RAW("    }\n")
15489
0
SLANG_RAW("}\n")
15490
0
SLANG_RAW("\n")
15491
0
SLANG_RAW("/// Truncate to integer.\n")
15492
0
SLANG_RAW("/// @category math\n")
15493
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType>\n")
15494
0
SLANG_RAW("[__readNone]\n")
15495
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15496
0
SLANG_RAW("T trunc(T x)\n")
15497
0
SLANG_RAW("{\n")
15498
0
SLANG_RAW("    __target_switch\n")
15499
0
SLANG_RAW("    {\n")
15500
0
SLANG_RAW("    case cpp: __intrinsic_asm \"$P_trunc($0)\";\n")
15501
0
SLANG_RAW("    case cuda: __intrinsic_asm \"$P_trunc($0)\";\n")
15502
0
SLANG_RAW("    case glsl: __intrinsic_asm \"trunc\";\n")
15503
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"trunc\";\n")
15504
0
SLANG_RAW("    case metal: __intrinsic_asm \"trunc\";\n")
15505
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15506
0
SLANG_RAW("        OpExtInst $$T result glsl450 Trunc $x\n")
15507
0
SLANG_RAW("    };\n")
15508
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"trunc\";\n")
15509
0
SLANG_RAW("    }\n")
15510
0
SLANG_RAW("}\n")
15511
0
SLANG_RAW("\n")
15512
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
15513
0
SLANG_RAW("[__readNone]\n")
15514
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15515
0
SLANG_RAW("vector<T, N> trunc(vector<T, N> x)\n")
15516
0
SLANG_RAW("{\n")
15517
0
SLANG_RAW("    __target_switch\n")
15518
0
SLANG_RAW("    {\n")
15519
0
SLANG_RAW("    case glsl: __intrinsic_asm \"trunc\";\n")
15520
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"trunc\";\n")
15521
0
SLANG_RAW("    case metal: __intrinsic_asm \"trunc\";\n")
15522
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
15523
0
SLANG_RAW("        OpExtInst $$vector<T, N> result glsl450 Trunc $x\n")
15524
0
SLANG_RAW("    };\n")
15525
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"trunc\";\n")
15526
0
SLANG_RAW("    default:\n")
15527
0
SLANG_RAW("        VECTOR_MAP_UNARY(T, N, trunc, x);\n")
15528
0
SLANG_RAW("    }\n")
15529
0
SLANG_RAW("}\n")
15530
0
SLANG_RAW("\n")
15531
0
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n")
15532
0
SLANG_RAW("[__readNone]\n")
15533
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_4_0_version)]\n")
15534
0
SLANG_RAW("matrix<T, N, M> trunc(matrix<T, N, M> x)\n")
15535
0
SLANG_RAW("{\n")
15536
0
SLANG_RAW("    __target_switch\n")
15537
0
SLANG_RAW("    {\n")
15538
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"trunc\";\n")
15539
0
SLANG_RAW("    default:\n")
15540
0
SLANG_RAW("        MATRIX_MAP_UNARY(T, N, M, trunc, x);\n")
15541
0
SLANG_RAW("    }\n")
15542
0
SLANG_RAW("}\n")
15543
0
SLANG_RAW("\n")
15544
0
SLANG_RAW("// Slang Specific 'Mask' Wave Intrinsics\n")
15545
0
SLANG_RAW("\n")
15546
0
SLANG_RAW("//@hidden:\n")
15547
0
SLANG_RAW("typedef uint WaveMask;\n")
15548
0
SLANG_RAW("\n")
15549
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15550
0
SLANG_RAW("__spirv_version(1.3)\n")
15551
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
15552
0
SLANG_RAW("WaveMask WaveGetConvergedMask()\n")
15553
0
SLANG_RAW("{\n")
15554
0
SLANG_RAW("    __target_switch\n")
15555
0
SLANG_RAW("    {\n")
15556
0
SLANG_RAW("    case glsl:\n")
15557
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallot(true).x\";\n")
15558
0
SLANG_RAW("    case hlsl:\n")
15559
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBallot(true).x\";\n")
15560
0
SLANG_RAW("    case cuda:\n")
15561
0
SLANG_RAW("        __intrinsic_asm \"__activemask()\";\n")
15562
0
SLANG_RAW("    case spirv:\n")
15563
0
SLANG_RAW("        let _true = true;\n")
15564
0
SLANG_RAW("        return (spirv_asm\n")
15565
0
SLANG_RAW("        {\n")
15566
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15567
0
SLANG_RAW("            OpGroupNonUniformBallot $$uint4 result Subgroup $_true\n")
15568
0
SLANG_RAW("        }).x;\n")
15569
0
SLANG_RAW("    }\n")
15570
0
SLANG_RAW("}\n")
15571
0
SLANG_RAW("\n")
15572
0
SLANG_RAW("__intrinsic_op(")
15573
0
SLANG_SPLICE(kIROp_WaveGetActiveMask
15574
0
)
15575
0
SLANG_RAW(")\n")
15576
0
SLANG_RAW("WaveMask __WaveGetActiveMask();\n")
15577
0
SLANG_RAW("\n")
15578
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15579
0
SLANG_RAW("__spirv_version(1.3)\n")
15580
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, subgroup_ballot_activemask)]\n")
15581
0
SLANG_RAW("WaveMask WaveGetActiveMask()\n")
15582
0
SLANG_RAW("{\n")
15583
0
SLANG_RAW("    __target_switch\n")
15584
0
SLANG_RAW("    {\n")
15585
0
SLANG_RAW("    case glsl:\n")
15586
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallot(true).x\";\n")
15587
0
SLANG_RAW("    case hlsl:\n")
15588
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBallot(true).x\";\n")
15589
0
SLANG_RAW("    case metal:\n")
15590
0
SLANG_RAW("        __intrinsic_asm \"((uint32_t)((simd_vote::vote_t)simd_ballot(true)))\";\n")
15591
0
SLANG_RAW("    case spirv:\n")
15592
0
SLANG_RAW("        let _true = true;\n")
15593
0
SLANG_RAW("        return (spirv_asm\n")
15594
0
SLANG_RAW("        {\n")
15595
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15596
0
SLANG_RAW("            OpGroupNonUniformBallot $$uint4 result Subgroup $_true\n")
15597
0
SLANG_RAW("        }).x;\n")
15598
0
SLANG_RAW("    case cuda:\n")
15599
0
SLANG_RAW("        return __WaveGetActiveMask();\n")
15600
0
SLANG_RAW("    }\n")
15601
0
SLANG_RAW("}\n")
15602
0
SLANG_RAW("\n")
15603
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_basic)\n")
15604
0
SLANG_RAW("__spirv_version(1.3)\n")
15605
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_basic)]\n")
15606
0
SLANG_RAW("bool WaveMaskIsFirstLane(WaveMask mask)\n")
15607
0
SLANG_RAW("{\n")
15608
0
SLANG_RAW("    __target_switch\n")
15609
0
SLANG_RAW("    {\n")
15610
0
SLANG_RAW("    case glsl:\n")
15611
0
SLANG_RAW("        __intrinsic_asm \"subgroupElect()\";\n")
15612
0
SLANG_RAW("    case cuda:\n")
15613
0
SLANG_RAW("        __intrinsic_asm \"(($0 & -$0) == (WarpMask(1) << _getLaneId()))\";\n")
15614
0
SLANG_RAW("    case hlsl:\n")
15615
0
SLANG_RAW("        __intrinsic_asm \"WaveIsFirstLane()\";\n")
15616
0
SLANG_RAW("    case spirv:\n")
15617
0
SLANG_RAW("        return spirv_asm\n")
15618
0
SLANG_RAW("        {\n")
15619
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15620
0
SLANG_RAW("            OpGroupNonUniformElect $$bool result Subgroup\n")
15621
0
SLANG_RAW("        };\n")
15622
0
SLANG_RAW("    }\n")
15623
0
SLANG_RAW("}\n")
15624
0
SLANG_RAW("\n")
15625
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
15626
0
SLANG_RAW("__spirv_version(1.3)\n")
15627
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
15628
0
SLANG_RAW("bool WaveMaskAllTrue(WaveMask mask, bool condition)\n")
15629
0
SLANG_RAW("{\n")
15630
0
SLANG_RAW("    __target_switch\n")
15631
0
SLANG_RAW("    {\n")
15632
0
SLANG_RAW("    case glsl:\n")
15633
0
SLANG_RAW("        __intrinsic_asm \"subgroupAll($1)\";\n")
15634
0
SLANG_RAW("    case cuda:\n")
15635
0
SLANG_RAW("        __intrinsic_asm \"(__all_sync($0, $1) != 0)\";\n")
15636
0
SLANG_RAW("    case hlsl:\n")
15637
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllTrue($1)\";\n")
15638
0
SLANG_RAW("    case spirv:\n")
15639
0
SLANG_RAW("        return spirv_asm\n")
15640
0
SLANG_RAW("        {\n")
15641
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15642
0
SLANG_RAW("            OpGroupNonUniformAll $$bool result Subgroup $condition\n")
15643
0
SLANG_RAW("        };\n")
15644
0
SLANG_RAW("    }\n")
15645
0
SLANG_RAW("}\n")
15646
0
SLANG_RAW("\n")
15647
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
15648
0
SLANG_RAW("__spirv_version(1.3)\n")
15649
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
15650
0
SLANG_RAW("bool WaveMaskAnyTrue(WaveMask mask, bool condition)\n")
15651
0
SLANG_RAW("{\n")
15652
0
SLANG_RAW("    __target_switch\n")
15653
0
SLANG_RAW("    {\n")
15654
0
SLANG_RAW("    case glsl:\n")
15655
0
SLANG_RAW("        __intrinsic_asm \"subgroupAny($1)\";\n")
15656
0
SLANG_RAW("    case cuda:\n")
15657
0
SLANG_RAW("        __intrinsic_asm \"(__any_sync($0, $1) != 0)\";\n")
15658
0
SLANG_RAW("    case hlsl:\n")
15659
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAnyTrue($1)\";\n")
15660
0
SLANG_RAW("    case spirv:\n")
15661
0
SLANG_RAW("        return spirv_asm\n")
15662
0
SLANG_RAW("        {\n")
15663
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15664
0
SLANG_RAW("            OpGroupNonUniformAny $$bool result Subgroup $condition\n")
15665
0
SLANG_RAW("        };\n")
15666
0
SLANG_RAW("    }\n")
15667
0
SLANG_RAW("}\n")
15668
0
SLANG_RAW("\n")
15669
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15670
0
SLANG_RAW("__spirv_version(1.3)\n")
15671
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
15672
0
SLANG_RAW("WaveMask WaveMaskBallot(WaveMask mask, bool condition)\n")
15673
0
SLANG_RAW("{\n")
15674
0
SLANG_RAW("    __target_switch\n")
15675
0
SLANG_RAW("    {\n")
15676
0
SLANG_RAW("    case glsl:\n")
15677
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallot($1).x\";\n")
15678
0
SLANG_RAW("    case cuda:\n")
15679
0
SLANG_RAW("        __intrinsic_asm \"__ballot_sync($0, $1)\";\n")
15680
0
SLANG_RAW("    case hlsl:\n")
15681
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBallot($1)\";\n")
15682
0
SLANG_RAW("    case spirv:\n")
15683
0
SLANG_RAW("        return (spirv_asm\n")
15684
0
SLANG_RAW("        {\n")
15685
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15686
0
SLANG_RAW("            OpGroupNonUniformBallot $$uint4 result Subgroup $condition\n")
15687
0
SLANG_RAW("        }).x;\n")
15688
0
SLANG_RAW("    }\n")
15689
0
SLANG_RAW("}\n")
15690
0
SLANG_RAW("\n")
15691
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_basic_ballot)]\n")
15692
0
SLANG_RAW("uint WaveMaskCountBits(WaveMask mask, bool value)\n")
15693
0
SLANG_RAW("{\n")
15694
0
SLANG_RAW("    __target_switch\n")
15695
0
SLANG_RAW("    {\n")
15696
0
SLANG_RAW("    case cuda:\n")
15697
0
SLANG_RAW("        __intrinsic_asm  \"__popc(__ballot_sync($0, $1))\";\n")
15698
0
SLANG_RAW("    case hlsl:\n")
15699
0
SLANG_RAW("        __intrinsic_asm  \"WaveActiveCountBits($1)\";\n")
15700
0
SLANG_RAW("    default:\n")
15701
0
SLANG_RAW("        return _WaveCountBits(WaveActiveBallot(value));\n")
15702
0
SLANG_RAW("    }\n")
15703
0
SLANG_RAW("}\n")
15704
0
SLANG_RAW("\n")
15705
0
SLANG_RAW("// Waits until all warp lanes named in mask have executed a WaveMaskSharedSync (with the same mask)\n")
15706
0
SLANG_RAW("// before resuming execution. Guarantees memory ordering in shared memory among threads participating\n")
15707
0
SLANG_RAW("// in the barrier.\n")
15708
0
SLANG_RAW("//\n")
15709
0
SLANG_RAW("// The CUDA intrinsic says it orders *all* memory accesses, which appears to match most closely subgroupBarrier.\n")
15710
0
SLANG_RAW("//\n")
15711
0
SLANG_RAW("// TODO(JS):\n")
15712
0
SLANG_RAW("// For HLSL it's not clear what to do. There is no explicit mechanism to 'reconverge' threads. In the docs it describes\n")
15713
0
SLANG_RAW("// behavior as\n")
15714
0
SLANG_RAW("// \"These intrinsics are dependent on active lanes and therefore flow control. In the model of this document, implementations\n")
15715
0
SLANG_RAW("// must enforce that the number of active lanes exactly corresponds to the programmer429496726642949671684294967193s view of flow control.\"\n")
15716
0
SLANG_RAW("//\n")
15717
0
SLANG_RAW("// It seems this can only mean the active threads are the \"threads the program flow would lead to\". This implies a lockstep\n")
15718
0
SLANG_RAW("// \"straight SIMD\" style interpretation. That being the case this op on HLSL is just a memory barrier without any Sync.\n")
15719
0
SLANG_RAW("\n")
15720
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, memorybarrier)]\n")
15721
0
SLANG_RAW("void AllMemoryBarrierWithWaveMaskSync(WaveMask mask)\n")
15722
0
SLANG_RAW("{\n")
15723
0
SLANG_RAW("    __target_switch\n")
15724
0
SLANG_RAW("    {\n")
15725
0
SLANG_RAW("    case cuda:\n")
15726
0
SLANG_RAW("        __intrinsic_asm \"__syncwarp($0)\";\n")
15727
0
SLANG_RAW("    case hlsl:\n")
15728
0
SLANG_RAW("        __intrinsic_asm \"AllMemoryBarrier()\";\n")
15729
0
SLANG_RAW("    case glsl:\n")
15730
0
SLANG_RAW("    case spirv:\n")
15731
0
SLANG_RAW("        __subgroupBarrier();\n")
15732
0
SLANG_RAW("        return;\n")
15733
0
SLANG_RAW("    }\n")
15734
0
SLANG_RAW("}\n")
15735
0
SLANG_RAW("\n")
15736
0
SLANG_RAW("// On GLSL, it appears we can't use subgroupMemoryBarrierShared, because it only implies a memory ordering, it does not\n")
15737
0
SLANG_RAW("// imply convergence. For subgroupBarrier we have from the docs..\n")
15738
0
SLANG_RAW("// \"The function subgroupBarrier() enforces that all active invocations within a subgroup must execute this function before any\n")
15739
0
SLANG_RAW("// are allowed to continue their execution\"\n")
15740
0
SLANG_RAW("// TODO(JS):\n")
15741
0
SLANG_RAW("// It's not entirely clear what to do here on HLSL.\n")
15742
0
SLANG_RAW("// Reading the dxc wiki (https://github.com/Microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics), we have statements like:\n")
15743
0
SLANG_RAW("//    ... these intrinsics enable the elimination of barrier constructs when the scope of synchronization is within the width of the SIMD processor.\n")
15744
0
SLANG_RAW("//    Wave: A set of lanes executed simultaneously in the processor. No explicit barriers are required to guarantee that they execute in parallel.\n")
15745
0
SLANG_RAW("// Which seems to imply at least some memory barriers like Shared might not be needed.\n")
15746
0
SLANG_RAW("//\n")
15747
0
SLANG_RAW("// The barrier is left here though, because not only is the barrier make writes before the barrier across the wave appear to others afterwards, it's\n")
15748
0
SLANG_RAW("// also there to inform the compiler on what order reads and writes can take place. This might seem to be silly because of the 'Active' lanes\n")
15749
0
SLANG_RAW("// aspect of HLSL seems to make everything in lock step - but that's not quite so, it only has to apparently be that way as far as the programmers\n")
15750
0
SLANG_RAW("// model appears - divergence could perhaps potentially still happen.\n")
15751
0
SLANG_RAW("\n")
15752
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, memorybarrier)]\n")
15753
0
SLANG_RAW("void GroupMemoryBarrierWithWaveMaskSync(WaveMask mask)\n")
15754
0
SLANG_RAW("{\n")
15755
0
SLANG_RAW("    __target_switch\n")
15756
0
SLANG_RAW("    {\n")
15757
0
SLANG_RAW("    case cuda:\n")
15758
0
SLANG_RAW("        __intrinsic_asm \"__syncwarp($0)\";\n")
15759
0
SLANG_RAW("    case hlsl:\n")
15760
0
SLANG_RAW("        __intrinsic_asm \"GroupMemoryBarrier()\";\n")
15761
0
SLANG_RAW("    case glsl:\n")
15762
0
SLANG_RAW("    case spirv:\n")
15763
0
SLANG_RAW("        __subgroupBarrier();\n")
15764
0
SLANG_RAW("        return;\n")
15765
0
SLANG_RAW("    }\n")
15766
0
SLANG_RAW("}\n")
15767
0
SLANG_RAW("\n")
15768
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, memorybarrier)]\n")
15769
0
SLANG_RAW("void AllMemoryBarrierWithWaveSync()\n")
15770
0
SLANG_RAW("{\n")
15771
0
SLANG_RAW("    __target_switch\n")
15772
0
SLANG_RAW("    {\n")
15773
0
SLANG_RAW("    case cuda:\n")
15774
0
SLANG_RAW("        __intrinsic_asm \"__syncwarp()\";\n")
15775
0
SLANG_RAW("    case hlsl:\n")
15776
0
SLANG_RAW("        __intrinsic_asm \"AllMemoryBarrier()\";\n")
15777
0
SLANG_RAW("    case glsl:\n")
15778
0
SLANG_RAW("    case spirv:\n")
15779
0
SLANG_RAW("        __subgroupBarrier();\n")
15780
0
SLANG_RAW("        return;\n")
15781
0
SLANG_RAW("    }\n")
15782
0
SLANG_RAW("}\n")
15783
0
SLANG_RAW("\n")
15784
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, memorybarrier)]\n")
15785
0
SLANG_RAW("void GroupMemoryBarrierWithWaveSync()\n")
15786
0
SLANG_RAW("{\n")
15787
0
SLANG_RAW("    __target_switch\n")
15788
0
SLANG_RAW("    {\n")
15789
0
SLANG_RAW("    case cuda:\n")
15790
0
SLANG_RAW("        __intrinsic_asm \"__syncwarp()\";\n")
15791
0
SLANG_RAW("    case hlsl:\n")
15792
0
SLANG_RAW("        __intrinsic_asm \"GroupMemoryBarrier()\";\n")
15793
0
SLANG_RAW("    case glsl:\n")
15794
0
SLANG_RAW("    case spirv:\n")
15795
0
SLANG_RAW("        __subgroupBarrier();\n")
15796
0
SLANG_RAW("        return;\n")
15797
0
SLANG_RAW("    }\n")
15798
0
SLANG_RAW("}\n")
15799
0
SLANG_RAW("\n")
15800
0
SLANG_RAW("// NOTE! WaveMaskBroadcastLaneAt is *NOT* standard HLSL\n")
15801
0
SLANG_RAW("// It is provided as access to subgroupBroadcast which can only take a\n")
15802
0
SLANG_RAW("// constexpr laneId.\n")
15803
0
SLANG_RAW("// https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_shader_subgroup.txt\n")
15804
0
SLANG_RAW("// Versions SPIR-V greater than 1.4 loosen this restriction, and allow 'dynamic uniform' index\n")
15805
0
SLANG_RAW("// If that's the behavior required then client code should use WaveReadLaneAt which works this way.\n")
15806
0
SLANG_RAW("\n")
15807
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
15808
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15809
0
SLANG_RAW("__spirv_version(1.3)\n")
15810
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
15811
0
SLANG_RAW("T WaveMaskBroadcastLaneAt(WaveMask mask, T value, constexpr int lane)\n")
15812
0
SLANG_RAW("{\n")
15813
0
SLANG_RAW("    __target_switch\n")
15814
0
SLANG_RAW("    {\n")
15815
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBroadcast($1, $2)\";\n")
15816
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__shfl_sync($0, $1, $2)\";\n")
15817
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15818
0
SLANG_RAW("    case spirv:\n")
15819
0
SLANG_RAW("        let ulane = uint(lane);\n")
15820
0
SLANG_RAW("        return spirv_asm {\n")
15821
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15822
0
SLANG_RAW("            OpGroupNonUniformBroadcast $$T result Subgroup $value $ulane;\n")
15823
0
SLANG_RAW("        };\n")
15824
0
SLANG_RAW("    }\n")
15825
0
SLANG_RAW("}\n")
15826
0
SLANG_RAW("\n")
15827
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
15828
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15829
0
SLANG_RAW("__spirv_version(1.3)\n")
15830
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
15831
0
SLANG_RAW("vector<T,N> WaveMaskBroadcastLaneAt(WaveMask mask, vector<T,N> value, constexpr int lane)\n")
15832
0
SLANG_RAW("{\n")
15833
0
SLANG_RAW("    __target_switch\n")
15834
0
SLANG_RAW("    {\n")
15835
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBroadcast($1, $2)\";\n")
15836
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple($0, $1, $2)\";\n")
15837
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15838
0
SLANG_RAW("    case spirv:\n")
15839
0
SLANG_RAW("        let ulane = uint(lane);\n")
15840
0
SLANG_RAW("        return spirv_asm {\n")
15841
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15842
0
SLANG_RAW("            OpGroupNonUniformBroadcast $$vector<T,N> result Subgroup $value $ulane;\n")
15843
0
SLANG_RAW("        };\n")
15844
0
SLANG_RAW("    }\n")
15845
0
SLANG_RAW("}\n")
15846
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
15847
0
SLANG_RAW("[require(cuda_hlsl, subgroup_ballot)]\n")
15848
0
SLANG_RAW("matrix<T,N,M> WaveMaskBroadcastLaneAt(WaveMask mask, matrix<T,N,M> value, constexpr int lane)\n")
15849
0
SLANG_RAW("{\n")
15850
0
SLANG_RAW("    __target_switch\n")
15851
0
SLANG_RAW("    {\n")
15852
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple($0, $1, $2)\";\n")
15853
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15854
0
SLANG_RAW("    }\n")
15855
0
SLANG_RAW("}\n")
15856
0
SLANG_RAW("\n")
15857
0
SLANG_RAW("// TODO(JS): If it can be determines that the `laneId` is constExpr, then subgroupBroadcast\n")
15858
0
SLANG_RAW("// could be used on GLSL. For now we just use subgroupShuffle\n")
15859
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
15860
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
15861
0
SLANG_RAW("__spirv_version(1.3)\n")
15862
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_shuffle)]\n")
15863
0
SLANG_RAW("T WaveMaskReadLaneAt(WaveMask mask, T value, int lane)\n")
15864
0
SLANG_RAW("{\n")
15865
0
SLANG_RAW("    __target_switch\n")
15866
0
SLANG_RAW("    {\n")
15867
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupShuffle($1, $2)\";\n")
15868
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__shfl_sync($0, $1, $2)\";\n")
15869
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15870
0
SLANG_RAW("    case spirv:\n")
15871
0
SLANG_RAW("        let ulane = uint(lane);\n")
15872
0
SLANG_RAW("        return spirv_asm {\n")
15873
0
SLANG_RAW("            OpCapability GroupNonUniformShuffle;\n")
15874
0
SLANG_RAW("            OpGroupNonUniformShuffle $$T result Subgroup $value $ulane;\n")
15875
0
SLANG_RAW("        };\n")
15876
0
SLANG_RAW("    }\n")
15877
0
SLANG_RAW("}\n")
15878
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
15879
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
15880
0
SLANG_RAW("__spirv_version(1.3)\n")
15881
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_shuffle)]\n")
15882
0
SLANG_RAW("vector<T,N> WaveMaskReadLaneAt(WaveMask mask, vector<T,N> value, int lane)\n")
15883
0
SLANG_RAW("{\n")
15884
0
SLANG_RAW("    __target_switch\n")
15885
0
SLANG_RAW("    {\n")
15886
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupShuffle($1, $2)\";\n")
15887
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple($0, $1, $2)\";\n")
15888
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15889
0
SLANG_RAW("    case spirv:\n")
15890
0
SLANG_RAW("        let ulane = uint(lane);\n")
15891
0
SLANG_RAW("        return spirv_asm {\n")
15892
0
SLANG_RAW("            OpCapability GroupNonUniformShuffle;\n")
15893
0
SLANG_RAW("            OpGroupNonUniformShuffle $$vector<T,N> result Subgroup $value $ulane;\n")
15894
0
SLANG_RAW("        };\n")
15895
0
SLANG_RAW("    }\n")
15896
0
SLANG_RAW("}\n")
15897
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
15898
0
SLANG_RAW("[require(cuda_hlsl, subgroup_shuffle)]\n")
15899
0
SLANG_RAW("matrix<T,N,M> WaveMaskReadLaneAt(WaveMask mask, matrix<T,N,M> value, int lane)\n")
15900
0
SLANG_RAW("{\n")
15901
0
SLANG_RAW("    __target_switch\n")
15902
0
SLANG_RAW("    {\n")
15903
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple($0, $1, $2)\";\n")
15904
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt($1, $2)\";\n")
15905
0
SLANG_RAW("    }\n")
15906
0
SLANG_RAW("}\n")
15907
0
SLANG_RAW("\n")
15908
0
SLANG_RAW("// NOTE! WaveMaskShuffle is a NON STANDARD HLSL intrinsic! It will map to WaveReadLaneAt on HLSL\n")
15909
0
SLANG_RAW("// which means it will only work on hardware which allows arbitrary laneIds which is not true\n")
15910
0
SLANG_RAW("// in general because it breaks the HLSL standard, which requires it's 'dynamically uniform' across the Wave.\n")
15911
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
15912
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
15913
0
SLANG_RAW("T WaveMaskShuffle(WaveMask mask, T value, int lane)\n")
15914
0
SLANG_RAW("{\n")
15915
0
SLANG_RAW("    return WaveMaskReadLaneAt(mask, value, lane);\n")
15916
0
SLANG_RAW("}\n")
15917
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
15918
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
15919
0
SLANG_RAW("vector<T,N> WaveMaskShuffle(WaveMask mask, vector<T,N> value, int lane)\n")
15920
0
SLANG_RAW("{\n")
15921
0
SLANG_RAW("    return WaveMaskReadLaneAt(mask, value, lane);\n")
15922
0
SLANG_RAW("}\n")
15923
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
15924
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
15925
0
SLANG_RAW("matrix<T,N,M> WaveMaskShuffle(WaveMask mask, matrix<T,N,M> value, int lane)\n")
15926
0
SLANG_RAW("{\n")
15927
0
SLANG_RAW("    return WaveMaskReadLaneAt(mask, value, lane);\n")
15928
0
SLANG_RAW("}\n")
15929
0
SLANG_RAW("\n")
15930
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
15931
0
SLANG_RAW("__spirv_version(1.3)\n")
15932
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
15933
0
SLANG_RAW("uint WaveMaskPrefixCountBits(WaveMask mask, bool value)\n")
15934
0
SLANG_RAW("{\n")
15935
0
SLANG_RAW("    __target_switch\n")
15936
0
SLANG_RAW("    {\n")
15937
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBallotExclusiveBitCount(subgroupBallot($1))\";\n")
15938
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__popc(__ballot_sync($0, $1)  & _getLaneLtMask())\";\n")
15939
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixCountBits($1)\";\n")
15940
0
SLANG_RAW("    case spirv:\n")
15941
0
SLANG_RAW("        return spirv_asm\n")
15942
0
SLANG_RAW("        {\n")
15943
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
15944
0
SLANG_RAW("            %mask:$$uint4 = OpGroupNonUniformBallot Subgroup $value;\n")
15945
0
SLANG_RAW("            OpGroupNonUniformBallotBitCount $$uint result Subgroup 2 %mask\n")
15946
0
SLANG_RAW("        };\n")
15947
0
SLANG_RAW("    }\n")
15948
0
SLANG_RAW("}\n")
15949
0
SLANG_RAW("\n")
15950
0
SLANG_RAW("// Across lane ops\n")
15951
0
SLANG_RAW("\n")
15952
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
15953
0
SLANG_RAW("[ForceInline]\n")
15954
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
15955
0
SLANG_RAW("T WaveMaskBitAnd(WaveMask mask, T expr)\n")
15956
0
SLANG_RAW("{\n")
15957
0
SLANG_RAW("    __target_switch\n")
15958
0
SLANG_RAW("    {\n")
15959
0
SLANG_RAW("    case hlsl:\n")
15960
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitAnd($1)\";\n")
15961
0
SLANG_RAW("    default:\n")
15962
0
SLANG_RAW("        return WaveMultiBitAnd(expr, uint4(mask, 0, 0, 0));\n")
15963
0
SLANG_RAW("    }\n")
15964
0
SLANG_RAW("}\n")
15965
0
SLANG_RAW("\n")
15966
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
15967
0
SLANG_RAW("[ForceInline]\n")
15968
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
15969
0
SLANG_RAW("vector<T,N> WaveMaskBitAnd(WaveMask mask, vector<T,N> expr)\n")
15970
0
SLANG_RAW("{\n")
15971
0
SLANG_RAW("    __target_switch\n")
15972
0
SLANG_RAW("    {\n")
15973
0
SLANG_RAW("    case hlsl:\n")
15974
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitAnd($1)\";\n")
15975
0
SLANG_RAW("    default:\n")
15976
0
SLANG_RAW("        return WaveMultiBitAnd(expr, uint4(mask, 0, 0, 0));\n")
15977
0
SLANG_RAW("    }\n")
15978
0
SLANG_RAW("}\n")
15979
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
15980
0
SLANG_RAW("[ForceInline]\n")
15981
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
15982
0
SLANG_RAW("matrix<T,N,M> WaveMaskBitAnd(WaveMask mask, matrix<T,N,M> expr)\n")
15983
0
SLANG_RAW("{\n")
15984
0
SLANG_RAW("    __target_switch\n")
15985
0
SLANG_RAW("    {\n")
15986
0
SLANG_RAW("    case hlsl:\n")
15987
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitAnd($1)\";\n")
15988
0
SLANG_RAW("    default:\n")
15989
0
SLANG_RAW("        return WaveMultiBitAnd(expr, uint4(mask, 0, 0, 0));\n")
15990
0
SLANG_RAW("    }\n")
15991
0
SLANG_RAW("}\n")
15992
0
SLANG_RAW("\n")
15993
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
15994
0
SLANG_RAW("[ForceInline]\n")
15995
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
15996
0
SLANG_RAW("T WaveMaskBitOr(WaveMask mask, T expr)\n")
15997
0
SLANG_RAW("{\n")
15998
0
SLANG_RAW("    __target_switch\n")
15999
0
SLANG_RAW("    {\n")
16000
0
SLANG_RAW("    case hlsl:\n")
16001
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitOr($1)\";\n")
16002
0
SLANG_RAW("    default:\n")
16003
0
SLANG_RAW("        return WaveMultiBitOr(expr, uint4(mask, 0, 0, 0));\n")
16004
0
SLANG_RAW("    }\n")
16005
0
SLANG_RAW("}\n")
16006
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16007
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16008
0
SLANG_RAW("[ForceInline]\n")
16009
0
SLANG_RAW("vector<T,N> WaveMaskBitOr(WaveMask mask, vector<T,N> expr)\n")
16010
0
SLANG_RAW("{\n")
16011
0
SLANG_RAW("    __target_switch\n")
16012
0
SLANG_RAW("    {\n")
16013
0
SLANG_RAW("    case hlsl:\n")
16014
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitOr($1)\";\n")
16015
0
SLANG_RAW("    default:\n")
16016
0
SLANG_RAW("        return WaveMultiBitOr(expr, uint4(mask, 0, 0, 0));\n")
16017
0
SLANG_RAW("    }\n")
16018
0
SLANG_RAW("}\n")
16019
0
SLANG_RAW("\n")
16020
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16021
0
SLANG_RAW("[ForceInline]\n")
16022
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16023
0
SLANG_RAW("matrix<T,N,M> WaveMaskBitOr(WaveMask mask, matrix<T,N,M> expr)\n")
16024
0
SLANG_RAW("{\n")
16025
0
SLANG_RAW("    __target_switch\n")
16026
0
SLANG_RAW("    {\n")
16027
0
SLANG_RAW("    case hlsl:\n")
16028
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitOr($1)\";\n")
16029
0
SLANG_RAW("    default:\n")
16030
0
SLANG_RAW("        return WaveMultiBitOr(expr, uint4(mask, 0, 0, 0));\n")
16031
0
SLANG_RAW("    }\n")
16032
0
SLANG_RAW("}\n")
16033
0
SLANG_RAW("\n")
16034
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
16035
0
SLANG_RAW("[ForceInline]\n")
16036
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16037
0
SLANG_RAW("T WaveMaskBitXor(WaveMask mask, T expr)\n")
16038
0
SLANG_RAW("{\n")
16039
0
SLANG_RAW("    __target_switch\n")
16040
0
SLANG_RAW("    {\n")
16041
0
SLANG_RAW("    case hlsl:\n")
16042
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitXor($1)\";\n")
16043
0
SLANG_RAW("    default:\n")
16044
0
SLANG_RAW("        return WaveMultiBitXor(expr, uint4(mask, 0, 0, 0));\n")
16045
0
SLANG_RAW("    }\n")
16046
0
SLANG_RAW("}\n")
16047
0
SLANG_RAW("\n")
16048
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16049
0
SLANG_RAW("[ForceInline]\n")
16050
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16051
0
SLANG_RAW("vector<T,N> WaveMaskBitXor(WaveMask mask, vector<T,N> expr)\n")
16052
0
SLANG_RAW("{\n")
16053
0
SLANG_RAW("    __target_switch\n")
16054
0
SLANG_RAW("    {\n")
16055
0
SLANG_RAW("    case hlsl:\n")
16056
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitXor($1)\";\n")
16057
0
SLANG_RAW("    default:\n")
16058
0
SLANG_RAW("        return WaveMultiBitXor(expr, uint4(mask, 0, 0, 0));\n")
16059
0
SLANG_RAW("    }\n")
16060
0
SLANG_RAW("}\n")
16061
0
SLANG_RAW("\n")
16062
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16063
0
SLANG_RAW("[ForceInline]\n")
16064
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16065
0
SLANG_RAW("matrix<T,N,M> WaveMaskBitXor(WaveMask mask, matrix<T,N,M> expr)\n")
16066
0
SLANG_RAW("{\n")
16067
0
SLANG_RAW("    __target_switch\n")
16068
0
SLANG_RAW("    {\n")
16069
0
SLANG_RAW("    case hlsl:\n")
16070
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBitXor($1)\";\n")
16071
0
SLANG_RAW("    default:\n")
16072
0
SLANG_RAW("        return WaveMultiBitXor(expr, uint4(mask, 0, 0, 0));\n")
16073
0
SLANG_RAW("    }\n")
16074
0
SLANG_RAW("}\n")
16075
0
SLANG_RAW("\n")
16076
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16077
0
SLANG_RAW("[ForceInline]\n")
16078
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16079
0
SLANG_RAW("T WaveMaskMax(WaveMask mask, T expr)\n")
16080
0
SLANG_RAW("{\n")
16081
0
SLANG_RAW("    __target_switch\n")
16082
0
SLANG_RAW("    {\n")
16083
0
SLANG_RAW("    case hlsl:\n")
16084
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMax($1)\";\n")
16085
0
SLANG_RAW("    default:\n")
16086
0
SLANG_RAW("        return WaveMultiMax(expr, uint4(mask, 0, 0, 0));\n")
16087
0
SLANG_RAW("    }\n")
16088
0
SLANG_RAW("}\n")
16089
0
SLANG_RAW("\n")
16090
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16091
0
SLANG_RAW("[ForceInline]\n")
16092
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16093
0
SLANG_RAW("vector<T,N> WaveMaskMax(WaveMask mask, vector<T,N> expr)\n")
16094
0
SLANG_RAW("{\n")
16095
0
SLANG_RAW("    __target_switch\n")
16096
0
SLANG_RAW("    {\n")
16097
0
SLANG_RAW("    case hlsl:\n")
16098
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMax($1)\";\n")
16099
0
SLANG_RAW("    default:\n")
16100
0
SLANG_RAW("        return WaveMultiMax(expr, uint4(mask, 0, 0, 0));\n")
16101
0
SLANG_RAW("    }\n")
16102
0
SLANG_RAW("}\n")
16103
0
SLANG_RAW("\n")
16104
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16105
0
SLANG_RAW("[ForceInline]\n")
16106
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16107
0
SLANG_RAW("matrix<T,N,M> WaveMaskMax(WaveMask mask, matrix<T,N,M> expr)\n")
16108
0
SLANG_RAW("{\n")
16109
0
SLANG_RAW("    __target_switch\n")
16110
0
SLANG_RAW("    {\n")
16111
0
SLANG_RAW("    case hlsl:\n")
16112
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMax($1)\";\n")
16113
0
SLANG_RAW("    default:\n")
16114
0
SLANG_RAW("        return WaveMultiMax(expr, uint4(mask, 0, 0, 0));\n")
16115
0
SLANG_RAW("    }\n")
16116
0
SLANG_RAW("}\n")
16117
0
SLANG_RAW("\n")
16118
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16119
0
SLANG_RAW("[ForceInline]\n")
16120
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16121
0
SLANG_RAW("T WaveMaskMin(WaveMask mask, T expr)\n")
16122
0
SLANG_RAW("{\n")
16123
0
SLANG_RAW("    __target_switch\n")
16124
0
SLANG_RAW("    {\n")
16125
0
SLANG_RAW("    case hlsl:\n")
16126
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMin($1)\";\n")
16127
0
SLANG_RAW("    default:\n")
16128
0
SLANG_RAW("        return WaveMultiMin(expr, uint4(mask, 0, 0, 0));\n")
16129
0
SLANG_RAW("    }\n")
16130
0
SLANG_RAW("}\n")
16131
0
SLANG_RAW("\n")
16132
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16133
0
SLANG_RAW("[ForceInline]\n")
16134
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16135
0
SLANG_RAW("vector<T,N> WaveMaskMin(WaveMask mask, vector<T,N> expr)\n")
16136
0
SLANG_RAW("{\n")
16137
0
SLANG_RAW("    __target_switch\n")
16138
0
SLANG_RAW("    {\n")
16139
0
SLANG_RAW("    case hlsl:\n")
16140
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMin($1)\";\n")
16141
0
SLANG_RAW("    default:\n")
16142
0
SLANG_RAW("        return WaveMultiMin(expr, uint4(mask, 0, 0, 0));\n")
16143
0
SLANG_RAW("    }\n")
16144
0
SLANG_RAW("}\n")
16145
0
SLANG_RAW("\n")
16146
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16147
0
SLANG_RAW("[ForceInline]\n")
16148
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16149
0
SLANG_RAW("matrix<T,N,M> WaveMaskMin(WaveMask mask, matrix<T,N,M> expr)\n")
16150
0
SLANG_RAW("{\n")
16151
0
SLANG_RAW("    __target_switch\n")
16152
0
SLANG_RAW("    {\n")
16153
0
SLANG_RAW("    case hlsl:\n")
16154
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveMin($1)\";\n")
16155
0
SLANG_RAW("    default:\n")
16156
0
SLANG_RAW("        return WaveMultiMin(expr, uint4(mask, 0, 0, 0));\n")
16157
0
SLANG_RAW("    }\n")
16158
0
SLANG_RAW("}\n")
16159
0
SLANG_RAW("\n")
16160
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16161
0
SLANG_RAW("[ForceInline]\n")
16162
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16163
0
SLANG_RAW("T WaveMaskProduct(WaveMask mask, T expr)\n")
16164
0
SLANG_RAW("{\n")
16165
0
SLANG_RAW("    __target_switch\n")
16166
0
SLANG_RAW("    {\n")
16167
0
SLANG_RAW("    case hlsl:\n")
16168
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveProduct($1)\";\n")
16169
0
SLANG_RAW("    default:\n")
16170
0
SLANG_RAW("        return WaveMultiProduct(expr, uint4(mask, 0, 0, 0));\n")
16171
0
SLANG_RAW("    }\n")
16172
0
SLANG_RAW("}\n")
16173
0
SLANG_RAW("\n")
16174
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16175
0
SLANG_RAW("[ForceInline]\n")
16176
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16177
0
SLANG_RAW("vector<T,N> WaveMaskProduct(WaveMask mask, vector<T,N> expr)\n")
16178
0
SLANG_RAW("{\n")
16179
0
SLANG_RAW("    __target_switch\n")
16180
0
SLANG_RAW("    {\n")
16181
0
SLANG_RAW("    case hlsl:\n")
16182
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveProduct($1)\";\n")
16183
0
SLANG_RAW("    default:\n")
16184
0
SLANG_RAW("        return WaveMultiProduct(expr, uint4(mask, 0, 0, 0));\n")
16185
0
SLANG_RAW("    }\n")
16186
0
SLANG_RAW("}\n")
16187
0
SLANG_RAW("\n")
16188
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16189
0
SLANG_RAW("[ForceInline]\n")
16190
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16191
0
SLANG_RAW("matrix<T,N,M> WaveMaskProduct(WaveMask mask, matrix<T,N,M> expr)\n")
16192
0
SLANG_RAW("{\n")
16193
0
SLANG_RAW("    __target_switch\n")
16194
0
SLANG_RAW("    {\n")
16195
0
SLANG_RAW("    case hlsl:\n")
16196
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveProduct($1)\";\n")
16197
0
SLANG_RAW("    default:\n")
16198
0
SLANG_RAW("        return WaveMultiProduct(expr, uint4(mask, 0, 0, 0));\n")
16199
0
SLANG_RAW("    }\n")
16200
0
SLANG_RAW("}\n")
16201
0
SLANG_RAW("\n")
16202
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16203
0
SLANG_RAW("[ForceInline]\n")
16204
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16205
0
SLANG_RAW("T WaveMaskSum(WaveMask mask, T expr)\n")
16206
0
SLANG_RAW("{\n")
16207
0
SLANG_RAW("    __target_switch\n")
16208
0
SLANG_RAW("    {\n")
16209
0
SLANG_RAW("    case hlsl:\n")
16210
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveSum($1)\";\n")
16211
0
SLANG_RAW("    default:\n")
16212
0
SLANG_RAW("        return WaveMultiSum(expr, uint4(mask, 0, 0, 0));\n")
16213
0
SLANG_RAW("    }\n")
16214
0
SLANG_RAW("}\n")
16215
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16216
0
SLANG_RAW("[ForceInline]\n")
16217
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16218
0
SLANG_RAW("vector<T,N> WaveMaskSum(WaveMask mask, vector<T,N> expr)\n")
16219
0
SLANG_RAW("{\n")
16220
0
SLANG_RAW("    __target_switch\n")
16221
0
SLANG_RAW("    {\n")
16222
0
SLANG_RAW("    case hlsl:\n")
16223
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveSum($1)\";\n")
16224
0
SLANG_RAW("    default:\n")
16225
0
SLANG_RAW("        return WaveMultiSum(expr, uint4(mask, 0, 0, 0));\n")
16226
0
SLANG_RAW("    }\n")
16227
0
SLANG_RAW("}\n")
16228
0
SLANG_RAW("\n")
16229
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16230
0
SLANG_RAW("[ForceInline]\n")
16231
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16232
0
SLANG_RAW("matrix<T,N,M> WaveMaskSum(WaveMask mask, matrix<T,N,M> expr)\n")
16233
0
SLANG_RAW("{\n")
16234
0
SLANG_RAW("    __target_switch\n")
16235
0
SLANG_RAW("    {\n")
16236
0
SLANG_RAW("    case hlsl:\n")
16237
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveSum($1)\";\n")
16238
0
SLANG_RAW("    default:\n")
16239
0
SLANG_RAW("        return WaveMultiSum(expr, uint4(mask, 0, 0, 0));\n")
16240
0
SLANG_RAW("    }\n")
16241
0
SLANG_RAW("}\n")
16242
0
SLANG_RAW("\n")
16243
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16244
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
16245
0
SLANG_RAW("__spirv_version(1.3)\n")
16246
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16247
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
16248
0
SLANG_RAW("bool WaveMaskAllEqual(WaveMask mask, T value)\n")
16249
0
SLANG_RAW("{\n")
16250
0
SLANG_RAW("    __target_switch\n")
16251
0
SLANG_RAW("    {\n")
16252
0
SLANG_RAW("    case glsl:\n")
16253
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
16254
0
SLANG_RAW("        __intrinsic_asm \"subgroupAllEqual($1)\";\n")
16255
0
SLANG_RAW("    case hlsl:\n")
16256
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllEqual($1)\";\n")
16257
0
SLANG_RAW("    case cuda:\n")
16258
0
SLANG_RAW("        __intrinsic_asm \"_waveAllEqual($0, $1)\";\n")
16259
0
SLANG_RAW("    case spirv:\n")
16260
0
SLANG_RAW("        return spirv_asm\n")
16261
0
SLANG_RAW("        {\n")
16262
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
16263
0
SLANG_RAW("            OpGroupNonUniformAllEqual $$bool result Subgroup $value\n")
16264
0
SLANG_RAW("        };\n")
16265
0
SLANG_RAW("    }\n")
16266
0
SLANG_RAW("}\n")
16267
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16268
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
16269
0
SLANG_RAW("__spirv_version(1.3)\n")
16270
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16271
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
16272
0
SLANG_RAW("bool WaveMaskAllEqual(WaveMask mask, vector<T,N> value)\n")
16273
0
SLANG_RAW("{\n")
16274
0
SLANG_RAW("    __target_switch\n")
16275
0
SLANG_RAW("    {\n")
16276
0
SLANG_RAW("    case glsl:\n")
16277
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
16278
0
SLANG_RAW("        __intrinsic_asm \"subgroupAllEqual($1)\";\n")
16279
0
SLANG_RAW("    case hlsl:\n")
16280
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllEqual($1)\";\n")
16281
0
SLANG_RAW("    case cuda:\n")
16282
0
SLANG_RAW("        __intrinsic_asm \"_waveAllEqualMultiple($0, $1)\";\n")
16283
0
SLANG_RAW("    case spirv:\n")
16284
0
SLANG_RAW("        return spirv_asm\n")
16285
0
SLANG_RAW("        {\n")
16286
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
16287
0
SLANG_RAW("            OpGroupNonUniformAllEqual $$bool result Subgroup $value\n")
16288
0
SLANG_RAW("        };\n")
16289
0
SLANG_RAW("    }\n")
16290
0
SLANG_RAW("}\n")
16291
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
16292
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16293
0
SLANG_RAW("[require(cuda_hlsl, subgroup_vote)]\n")
16294
0
SLANG_RAW("bool WaveMaskAllEqual(WaveMask mask, matrix<T,N,M> value)\n")
16295
0
SLANG_RAW("{\n")
16296
0
SLANG_RAW("    __target_switch\n")
16297
0
SLANG_RAW("    {\n")
16298
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveAllEqualMultiple($0, $1)\";\n")
16299
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActiveAllEqual($1)\";\n")
16300
0
SLANG_RAW("    }\n")
16301
0
SLANG_RAW("}\n")
16302
0
SLANG_RAW("\n")
16303
0
SLANG_RAW("// Prefix\n")
16304
0
SLANG_RAW("\n")
16305
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16306
0
SLANG_RAW("[ForceInline]\n")
16307
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16308
0
SLANG_RAW("T WaveMaskPrefixProduct(WaveMask mask, T expr)\n")
16309
0
SLANG_RAW("{\n")
16310
0
SLANG_RAW("    return WaveMultiPrefixProduct(expr, uint4(mask, 0, 0, 0));\n")
16311
0
SLANG_RAW("}\n")
16312
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16313
0
SLANG_RAW("[ForceInline]\n")
16314
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16315
0
SLANG_RAW("vector<T,N> WaveMaskPrefixProduct(WaveMask mask, vector<T,N> expr)\n")
16316
0
SLANG_RAW("{\n")
16317
0
SLANG_RAW("    return WaveMultiPrefixProduct(expr, uint4(mask, 0, 0, 0));\n")
16318
0
SLANG_RAW("}\n")
16319
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16320
0
SLANG_RAW("[ForceInline]\n")
16321
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16322
0
SLANG_RAW("matrix<T,N,M> WaveMaskPrefixProduct(WaveMask mask, matrix<T,N,M> expr)\n")
16323
0
SLANG_RAW("{\n")
16324
0
SLANG_RAW("    return WaveMultiPrefixProduct(expr, uint4(mask, 0, 0, 0));\n")
16325
0
SLANG_RAW("}\n")
16326
0
SLANG_RAW("\n")
16327
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16328
0
SLANG_RAW("[ForceInline]\n")
16329
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16330
0
SLANG_RAW("T WaveMaskPrefixSum(WaveMask mask, T expr)\n")
16331
0
SLANG_RAW("{\n")
16332
0
SLANG_RAW("    return WaveMultiPrefixSum(expr, uint4(mask, 0, 0, 0));\n")
16333
0
SLANG_RAW("}\n")
16334
0
SLANG_RAW("\n")
16335
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16336
0
SLANG_RAW("[ForceInline]\n")
16337
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16338
0
SLANG_RAW("vector<T,N> WaveMaskPrefixSum(WaveMask mask, vector<T,N> expr)\n")
16339
0
SLANG_RAW("{\n")
16340
0
SLANG_RAW("    return WaveMultiPrefixSum(expr, uint4(mask, 0, 0, 0));\n")
16341
0
SLANG_RAW("}\n")
16342
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16343
0
SLANG_RAW("[ForceInline]\n")
16344
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16345
0
SLANG_RAW("matrix<T,N,M> WaveMaskPrefixSum(WaveMask mask, matrix<T,N,M> expr)\n")
16346
0
SLANG_RAW("{\n")
16347
0
SLANG_RAW("    return WaveMultiPrefixSum(expr, uint4(mask, 0, 0, 0));\n")
16348
0
SLANG_RAW("}\n")
16349
0
SLANG_RAW("\n")
16350
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16351
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
16352
0
SLANG_RAW("__spirv_version(1.3)\n")
16353
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
16354
0
SLANG_RAW("T WaveMaskReadLaneFirst(WaveMask mask, T expr)\n")
16355
0
SLANG_RAW("{\n")
16356
0
SLANG_RAW("    __target_switch\n")
16357
0
SLANG_RAW("    {\n")
16358
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBroadcastFirst($1)\";\n")
16359
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveReadFirst($0, $1)\";\n")
16360
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneFirst($1)\";\n")
16361
0
SLANG_RAW("    case spirv:\n")
16362
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcastFirst $$T result Subgroup $expr};\n")
16363
0
SLANG_RAW("    }\n")
16364
0
SLANG_RAW("}\n")
16365
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16366
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
16367
0
SLANG_RAW("__spirv_version(1.3)\n")
16368
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
16369
0
SLANG_RAW("vector<T,N> WaveMaskReadLaneFirst(WaveMask mask, vector<T,N> expr)\n")
16370
0
SLANG_RAW("{\n")
16371
0
SLANG_RAW("    __target_switch\n")
16372
0
SLANG_RAW("    {\n")
16373
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupBroadcastFirst($1)\";\n")
16374
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveReadFirstMultiple($0, $1)\";\n")
16375
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneFirst($1)\";\n")
16376
0
SLANG_RAW("    case spirv:\n")
16377
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcastFirst $$vector<T,N> result Subgroup $expr};\n")
16378
0
SLANG_RAW("    }\n")
16379
0
SLANG_RAW("}\n")
16380
0
SLANG_RAW("\n")
16381
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
16382
0
SLANG_RAW("[require(cuda, subgroup_ballot)]\n")
16383
0
SLANG_RAW("matrix<T,N,M> WaveMaskReadLaneFirst(WaveMask mask, matrix<T,N,M> expr)\n")
16384
0
SLANG_RAW("{\n")
16385
0
SLANG_RAW("    __target_switch\n")
16386
0
SLANG_RAW("    {\n")
16387
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveReadFirstMultiple($0, $1)\";\n")
16388
0
SLANG_RAW("    }\n")
16389
0
SLANG_RAW("}\n")
16390
0
SLANG_RAW("\n")
16391
0
SLANG_RAW("// WaveMask SM6.5 like intrinsics\n")
16392
0
SLANG_RAW("\n")
16393
0
SLANG_RAW("// TODO(JS): On HLSL it only works for 32 bits or less\n")
16394
0
SLANG_RAW("\n")
16395
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16396
0
SLANG_RAW("__glsl_extension(GL_NV_shader_subgroup_partitioned)\n")
16397
0
SLANG_RAW("__spirv_version(1.1)\n")
16398
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16399
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16400
0
SLANG_RAW("WaveMask WaveMaskMatch(WaveMask mask, T value)\n")
16401
0
SLANG_RAW("{\n")
16402
0
SLANG_RAW("    __target_switch\n")
16403
0
SLANG_RAW("    {\n")
16404
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupPartitionNV($1).x\";\n")
16405
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveMatchScalar($0, $1).x\";\n")
16406
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch($1).x\";\n")
16407
0
SLANG_RAW("    case spirv:\n")
16408
0
SLANG_RAW("        return (spirv_asm\n")
16409
0
SLANG_RAW("        {\n")
16410
0
SLANG_RAW("            OpCapability GroupNonUniformPartitionedNV;\n")
16411
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_subgroup_partitioned\";\n")
16412
0
SLANG_RAW("            OpGroupNonUniformPartitionNV $$uint4 result $value\n")
16413
0
SLANG_RAW("        }).x;\n")
16414
0
SLANG_RAW("    }\n")
16415
0
SLANG_RAW("}\n")
16416
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16417
0
SLANG_RAW("__glsl_extension(GL_NV_shader_subgroup_partitioned)\n")
16418
0
SLANG_RAW("__spirv_version(1.1)\n")
16419
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16420
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16421
0
SLANG_RAW("WaveMask WaveMaskMatch(WaveMask mask, vector<T,N> value)\n")
16422
0
SLANG_RAW("{\n")
16423
0
SLANG_RAW("    __target_switch\n")
16424
0
SLANG_RAW("    {\n")
16425
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupPartitionNV($1).x\";\n")
16426
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveMatchMultiple($0, $1).x\";\n")
16427
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch($1).x\";\n")
16428
0
SLANG_RAW("    case spirv:\n")
16429
0
SLANG_RAW("        return (spirv_asm\n")
16430
0
SLANG_RAW("        {\n")
16431
0
SLANG_RAW("            OpCapability GroupNonUniformPartitionedNV;\n")
16432
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_subgroup_partitioned\";\n")
16433
0
SLANG_RAW("            OpGroupNonUniformPartitionNV $$uint4 result $value\n")
16434
0
SLANG_RAW("        }).x;\n")
16435
0
SLANG_RAW("    }\n")
16436
0
SLANG_RAW("}\n")
16437
0
SLANG_RAW("\n")
16438
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
16439
0
SLANG_RAW("__glsl_extension(GL_NV_shader_subgroup_partitioned)\n")
16440
0
SLANG_RAW("__spirv_version(1.3)\n")
16441
0
SLANG_RAW("__cuda_sm_version(7.0)\n")
16442
0
SLANG_RAW("[require(cuda_glsl_hlsl, subgroup_partitioned)]\n")
16443
0
SLANG_RAW("WaveMask WaveMaskMatch(WaveMask mask, matrix<T,N,M> value)\n")
16444
0
SLANG_RAW("{\n")
16445
0
SLANG_RAW("    __target_switch\n")
16446
0
SLANG_RAW("    {\n")
16447
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveMatchMultiple($0, $1)\";\n")
16448
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupPartitionNV($1).x\";\n")
16449
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch($1).x\";\n")
16450
0
SLANG_RAW("    }\n")
16451
0
SLANG_RAW("}\n")
16452
0
SLANG_RAW("\n")
16453
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
16454
0
SLANG_RAW("[ForceInline]\n")
16455
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16456
0
SLANG_RAW("T WaveMaskPrefixBitAnd(WaveMask mask, T expr)\n")
16457
0
SLANG_RAW("{\n")
16458
0
SLANG_RAW("    return WaveMultiPrefixBitAnd(expr, uint4(mask, 0, 0, 0));\n")
16459
0
SLANG_RAW("}\n")
16460
0
SLANG_RAW("\n")
16461
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16462
0
SLANG_RAW("[ForceInline]\n")
16463
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16464
0
SLANG_RAW("vector<T,N> WaveMaskPrefixBitAnd(WaveMask mask, vector<T,N> expr)\n")
16465
0
SLANG_RAW("{\n")
16466
0
SLANG_RAW("    return WaveMultiPrefixBitAnd(expr, uint4(mask, 0, 0, 0));\n")
16467
0
SLANG_RAW("}\n")
16468
0
SLANG_RAW("\n")
16469
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16470
0
SLANG_RAW("[ForceInline]\n")
16471
0
SLANG_RAW("[require(cuda_hlsl, subgroup_partitioned)]\n")
16472
0
SLANG_RAW("matrix<T,N,M> WaveMaskPrefixBitAnd(WaveMask mask, matrix<T,N,M> expr)\n")
16473
0
SLANG_RAW("{\n")
16474
0
SLANG_RAW("    return WaveMultiPrefixBitAnd(expr, uint4(mask, 0, 0, 0));\n")
16475
0
SLANG_RAW("}\n")
16476
0
SLANG_RAW("\n")
16477
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
16478
0
SLANG_RAW("[ForceInline]\n")
16479
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16480
0
SLANG_RAW("T WaveMaskPrefixBitOr(WaveMask mask, T expr)\n")
16481
0
SLANG_RAW("{\n")
16482
0
SLANG_RAW("    return WaveMultiPrefixBitOr(expr, uint4(mask, 0, 0, 0));\n")
16483
0
SLANG_RAW("}\n")
16484
0
SLANG_RAW("\n")
16485
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16486
0
SLANG_RAW("[ForceInline]\n")
16487
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16488
0
SLANG_RAW("vector<T,N> WaveMaskPrefixBitOr(WaveMask mask, vector<T,N> expr)\n")
16489
0
SLANG_RAW("{\n")
16490
0
SLANG_RAW("    return WaveMultiPrefixBitOr(expr, uint4(mask, 0, 0, 0));\n")
16491
0
SLANG_RAW("}\n")
16492
0
SLANG_RAW("\n")
16493
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16494
0
SLANG_RAW("[ForceInline]\n")
16495
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16496
0
SLANG_RAW("matrix<T,N,M> WaveMaskPrefixBitOr(WaveMask mask, matrix<T,N,M> expr)\n")
16497
0
SLANG_RAW("{\n")
16498
0
SLANG_RAW("    return WaveMultiPrefixBitOr(expr, uint4(mask, 0, 0, 0));\n")
16499
0
SLANG_RAW("}\n")
16500
0
SLANG_RAW("\n")
16501
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
16502
0
SLANG_RAW("[ForceInline]\n")
16503
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16504
0
SLANG_RAW("T WaveMaskPrefixBitXor(WaveMask mask, T expr)\n")
16505
0
SLANG_RAW("{\n")
16506
0
SLANG_RAW("    return WaveMultiPrefixBitXor(expr, uint4(mask, 0, 0, 0));\n")
16507
0
SLANG_RAW("}\n")
16508
0
SLANG_RAW("\n")
16509
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16510
0
SLANG_RAW("[ForceInline]\n")
16511
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16512
0
SLANG_RAW("vector<T,N> WaveMaskPrefixBitXor(WaveMask mask, vector<T,N> expr)\n")
16513
0
SLANG_RAW("{\n")
16514
0
SLANG_RAW("    return WaveMultiPrefixBitOr(expr, uint4(mask, 0, 0, 0));\n")
16515
0
SLANG_RAW("}\n")
16516
0
SLANG_RAW("\n")
16517
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16518
0
SLANG_RAW("[ForceInline]\n")
16519
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
16520
0
SLANG_RAW("matrix<T,N,M> WaveMaskPrefixBitXor(WaveMask mask, matrix<T,N,M> expr)\n")
16521
0
SLANG_RAW("{\n")
16522
0
SLANG_RAW("    return WaveMultiPrefixBitOr(expr, uint4(mask, 0, 0, 0));\n")
16523
0
SLANG_RAW("}\n")
16524
0
SLANG_RAW("\n")
16525
0
SLANG_RAW("//@public:\n")
16526
0
SLANG_RAW("\n")
16527
0
SLANG_RAW("// Shader model 6.0 stuff\n")
16528
0
SLANG_RAW("\n")
16529
0
SLANG_RAW("// Information for GLSL wave/subgroup support\n")
16530
0
SLANG_RAW("// https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_shader_subgroup.txt\n")
16531
0
SLANG_RAW("\n")
16532
0
SLANG_RAW("/// @category wave\n")
16533
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16534
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16535
0
SLANG_RAW("__spirv_version(1.3)\n")
16536
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, subgroup_quad)]\n")
16537
0
SLANG_RAW("T QuadReadLaneAt(T sourceValue, uint quadLaneID)\n")
16538
0
SLANG_RAW("{\n")
16539
0
SLANG_RAW("    __target_switch\n")
16540
0
SLANG_RAW("    {\n")
16541
0
SLANG_RAW("    case hlsl:\n")
16542
0
SLANG_RAW("        __intrinsic_asm \"QuadReadLaneAt\";\n")
16543
0
SLANG_RAW("    case glsl:\n")
16544
0
SLANG_RAW("        __intrinsic_asm \"subgroupQuadBroadcast\";\n")
16545
0
SLANG_RAW("    case metal:\n")
16546
0
SLANG_RAW("        // TODO: Need to add intrinsics to access Metal and WGSL's broadcast variant where lane is const for all threads.\n")
16547
0
SLANG_RAW("        __intrinsic_asm \"quad_shuffle($0, ushort($1))\";\n")
16548
0
SLANG_RAW("    case spirv:\n")
16549
0
SLANG_RAW("        return spirv_asm {\n")
16550
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16551
0
SLANG_RAW("            result:$$T = OpGroupNonUniformQuadBroadcast Subgroup $sourceValue $quadLaneID;\n")
16552
0
SLANG_RAW("        };\n")
16553
0
SLANG_RAW("    case cuda:\n")
16554
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, (_getLaneId() & 0xFFFFFFFC) | ($1 & 3))\";\n")
16555
0
SLANG_RAW("    }\n")
16556
0
SLANG_RAW("}\n")
16557
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16558
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16559
0
SLANG_RAW("__spirv_version(1.3)\n")
16560
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, subgroup_quad)]\n")
16561
0
SLANG_RAW("vector<T,N> QuadReadLaneAt(vector<T,N> sourceValue, uint quadLaneID)\n")
16562
0
SLANG_RAW("{\n")
16563
0
SLANG_RAW("    __target_switch\n")
16564
0
SLANG_RAW("    {\n")
16565
0
SLANG_RAW("    case hlsl:\n")
16566
0
SLANG_RAW("        __intrinsic_asm \"QuadReadLaneAt\";\n")
16567
0
SLANG_RAW("    case glsl:\n")
16568
0
SLANG_RAW("        __intrinsic_asm \"subgroupQuadBroadcast\";\n")
16569
0
SLANG_RAW("    case metal:\n")
16570
0
SLANG_RAW("        __intrinsic_asm \"quad_shuffle($0, ushort($1))\";\n")
16571
0
SLANG_RAW("    case spirv:\n")
16572
0
SLANG_RAW("        return spirv_asm {\n")
16573
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16574
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformQuadBroadcast Subgroup $sourceValue $quadLaneID;\n")
16575
0
SLANG_RAW("        };\n")
16576
0
SLANG_RAW("    case cuda:\n")
16577
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, (_getLaneId() & 0xFFFFFFFC) | ($1 & 3))\";\n")
16578
0
SLANG_RAW("    }\n")
16579
0
SLANG_RAW("}\n")
16580
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadReadLaneAt(matrix<T,N,M> sourceValue, uint quadLaneID);\n")
16581
0
SLANG_RAW("\n")
16582
0
SLANG_RAW("/// @category wave\n")
16583
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16584
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16585
0
SLANG_RAW("__spirv_version(1.3)\n")
16586
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16587
0
SLANG_RAW("[ForceInline]\n")
16588
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16589
0
SLANG_RAW("T QuadReadAcrossX(T localValue)\n")
16590
0
SLANG_RAW("{\n")
16591
0
SLANG_RAW("    __target_switch\n")
16592
0
SLANG_RAW("    {\n")
16593
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossX\";\n")
16594
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapHorizontal($0)\";\n")
16595
0
SLANG_RAW("    case metal:\n")
16596
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 1U);\n")
16597
0
SLANG_RAW("    case spirv:\n")
16598
0
SLANG_RAW("        uint direction = 0u;\n")
16599
0
SLANG_RAW("        return spirv_asm\n")
16600
0
SLANG_RAW("        {\n")
16601
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16602
0
SLANG_RAW("            result:$$T = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16603
0
SLANG_RAW("        };\n")
16604
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapX\";\n")
16605
0
SLANG_RAW("    case cuda:\n")
16606
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 1)\";\n")
16607
0
SLANG_RAW("    }\n")
16608
0
SLANG_RAW("}\n")
16609
0
SLANG_RAW("\n")
16610
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16611
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16612
0
SLANG_RAW("__spirv_version(1.3)\n")
16613
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16614
0
SLANG_RAW("[ForceInline]\n")
16615
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16616
0
SLANG_RAW("vector<T,N> QuadReadAcrossX(vector<T,N> localValue)\n")
16617
0
SLANG_RAW("{\n")
16618
0
SLANG_RAW("    __target_switch\n")
16619
0
SLANG_RAW("    {\n")
16620
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossX\";\n")
16621
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapHorizontal($0)\";\n")
16622
0
SLANG_RAW("    case metal:\n")
16623
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 1U);\n")
16624
0
SLANG_RAW("    case spirv:\n")
16625
0
SLANG_RAW("        uint direction = 0u;\n")
16626
0
SLANG_RAW("        return spirv_asm\n")
16627
0
SLANG_RAW("        {\n")
16628
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16629
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16630
0
SLANG_RAW("        };\n")
16631
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapX\";\n")
16632
0
SLANG_RAW("    case cuda:\n")
16633
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 1)\";\n")
16634
0
SLANG_RAW("    }\n")
16635
0
SLANG_RAW("}\n")
16636
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadReadAcrossX(matrix<T,N,M> localValue);\n")
16637
0
SLANG_RAW("\n")
16638
0
SLANG_RAW("/// @category wave\n")
16639
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16640
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16641
0
SLANG_RAW("__spirv_version(1.3)\n")
16642
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16643
0
SLANG_RAW("[ForceInline]\n")
16644
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16645
0
SLANG_RAW("T QuadReadAcrossY(T localValue)\n")
16646
0
SLANG_RAW("{\n")
16647
0
SLANG_RAW("    __target_switch\n")
16648
0
SLANG_RAW("    {\n")
16649
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossY\";\n")
16650
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapVertical($0)\";\n")
16651
0
SLANG_RAW("    case metal:\n")
16652
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 2U);\n")
16653
0
SLANG_RAW("    case spirv:\n")
16654
0
SLANG_RAW("        uint direction = 1u;\n")
16655
0
SLANG_RAW("        return spirv_asm\n")
16656
0
SLANG_RAW("        {\n")
16657
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16658
0
SLANG_RAW("            result:$$T = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16659
0
SLANG_RAW("        };\n")
16660
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapY\";\n")
16661
0
SLANG_RAW("    case cuda:\n")
16662
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 2)\";\n")
16663
0
SLANG_RAW("    }\n")
16664
0
SLANG_RAW("}\n")
16665
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16666
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16667
0
SLANG_RAW("__spirv_version(1.3)\n")
16668
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16669
0
SLANG_RAW("[ForceInline]\n")
16670
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16671
0
SLANG_RAW("vector<T,N> QuadReadAcrossY(vector<T,N> localValue)\n")
16672
0
SLANG_RAW("{\n")
16673
0
SLANG_RAW("    __target_switch\n")
16674
0
SLANG_RAW("    {\n")
16675
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossY\";\n")
16676
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapVertical($0)\";\n")
16677
0
SLANG_RAW("    case metal:\n")
16678
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 2U);\n")
16679
0
SLANG_RAW("    case spirv:\n")
16680
0
SLANG_RAW("        uint direction = 1u;\n")
16681
0
SLANG_RAW("        return spirv_asm\n")
16682
0
SLANG_RAW("        {\n")
16683
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16684
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16685
0
SLANG_RAW("        };\n")
16686
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapY\";\n")
16687
0
SLANG_RAW("    case cuda:\n")
16688
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 2)\";\n")
16689
0
SLANG_RAW("    }\n")
16690
0
SLANG_RAW("}\n")
16691
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadReadAcrossY(matrix<T,N,M> localValue);\n")
16692
0
SLANG_RAW("\n")
16693
0
SLANG_RAW("/// @category wave\n")
16694
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
16695
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16696
0
SLANG_RAW("__spirv_version(1.3)\n")
16697
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16698
0
SLANG_RAW("[ForceInline]\n")
16699
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16700
0
SLANG_RAW("T QuadReadAcrossDiagonal(T localValue)\n")
16701
0
SLANG_RAW("{\n")
16702
0
SLANG_RAW("    __target_switch\n")
16703
0
SLANG_RAW("    {\n")
16704
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossDiagonal\";\n")
16705
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapDiagonal($0)\";\n")
16706
0
SLANG_RAW("    case metal:\n")
16707
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 3U);\n")
16708
0
SLANG_RAW("    case spirv:\n")
16709
0
SLANG_RAW("        uint direction = 2u;\n")
16710
0
SLANG_RAW("        return spirv_asm\n")
16711
0
SLANG_RAW("        {\n")
16712
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16713
0
SLANG_RAW("            result:$$T = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16714
0
SLANG_RAW("        };\n")
16715
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapDiagonal\";\n")
16716
0
SLANG_RAW("    case cuda:\n")
16717
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 3)\";\n")
16718
0
SLANG_RAW("    }\n")
16719
0
SLANG_RAW("}\n")
16720
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
16721
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_quad)\n")
16722
0
SLANG_RAW("__spirv_version(1.3)\n")
16723
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16724
0
SLANG_RAW("[ForceInline]\n")
16725
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_quad)]\n")
16726
0
SLANG_RAW("vector<T,N> QuadReadAcrossDiagonal(vector<T,N> localValue)\n")
16727
0
SLANG_RAW("{\n")
16728
0
SLANG_RAW("    __target_switch\n")
16729
0
SLANG_RAW("    {\n")
16730
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadReadAcrossDiagonal\";\n")
16731
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadSwapDiagonal($0)\";\n")
16732
0
SLANG_RAW("    case metal:\n")
16733
0
SLANG_RAW("        return QuadReadLaneAt(localValue, __builtinQuadLaneIndex ^ 3U);\n")
16734
0
SLANG_RAW("    case spirv:\n")
16735
0
SLANG_RAW("        uint direction = 2u;\n")
16736
0
SLANG_RAW("        return spirv_asm\n")
16737
0
SLANG_RAW("        {\n")
16738
0
SLANG_RAW("            OpCapability GroupNonUniformQuad;\n")
16739
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformQuadSwap Subgroup $localValue $direction;\n")
16740
0
SLANG_RAW("        };\n")
16741
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"quadSwapDiagonal\";\n")
16742
0
SLANG_RAW("    case cuda:\n")
16743
0
SLANG_RAW("        __intrinsic_asm \"_waveShuffleMultiple(0xFFFFFFFF, $0, _getLaneId() ^ 3)\";\n")
16744
0
SLANG_RAW("    }\n")
16745
0
SLANG_RAW("}\n")
16746
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadReadAcrossDiagonal(matrix<T,N,M> localValue);\n")
16747
0
SLANG_RAW("\n")
16748
0
SLANG_RAW("// WaveActiveBitAnd, WaveActiveBitOr, WaveActiveBitXor\n")
16749
16750
0
struct WaveActiveBitOpEntry { const char* hlslName; const char* glslName; const char* spirvName; const char* metalName; };
16751
0
const WaveActiveBitOpEntry kWaveActiveBitOpEntries[] = {{"BitAnd", "And", "BitwiseAnd", "and"}, {"BitOr", "Or", "BitwiseOr", "or"}, {"BitXor", "Xor", "BitwiseXor", "xor"}};
16752
0
for (auto opName : kWaveActiveBitOpEntries) {
16753
0
SLANG_RAW("#line 15257 \"hlsl.meta.slang\"")
16754
0
SLANG_RAW("\n")
16755
0
SLANG_RAW("/// @category wave Wave and quad functions\n")
16756
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
16757
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
16758
0
SLANG_RAW("__spirv_version(1.3)\n")
16759
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16760
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16761
0
SLANG_RAW("T WaveActive")
16762
0
SLANG_SPLICE(opName.hlslName
16763
0
)
16764
0
SLANG_RAW("(T expr)\n")
16765
0
SLANG_RAW("{\n")
16766
0
SLANG_RAW("    __target_switch\n")
16767
0
SLANG_RAW("    {\n")
16768
0
SLANG_RAW("    case glsl:\n")
16769
0
SLANG_RAW("    case wgsl:\n")
16770
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
16771
0
SLANG_SPLICE(opName.glslName
16772
0
)
16773
0
SLANG_RAW("\";\n")
16774
0
SLANG_RAW("    case hlsl:\n")
16775
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
16776
0
SLANG_SPLICE(opName.hlslName
16777
0
)
16778
0
SLANG_RAW("\";\n")
16779
0
SLANG_RAW("    case metal:\n")
16780
0
SLANG_RAW("        __intrinsic_asm \"simd_")
16781
0
SLANG_SPLICE(opName.metalName
16782
0
)
16783
0
SLANG_RAW("\";\n")
16784
0
SLANG_RAW("    case spirv:\n")
16785
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniform")
16786
0
SLANG_SPLICE(opName.spirvName
16787
0
)
16788
0
SLANG_RAW(" $$T result Subgroup Reduce $expr};\n")
16789
0
SLANG_RAW("    case cuda:\n")
16790
0
SLANG_RAW("        return WaveMask")
16791
0
SLANG_SPLICE(opName.hlslName
16792
0
)
16793
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16794
0
SLANG_RAW("    }\n")
16795
0
SLANG_RAW("}\n")
16796
0
SLANG_RAW("\n")
16797
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
16798
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
16799
0
SLANG_RAW("__spirv_version(1.3)\n")
16800
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16801
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16802
0
SLANG_RAW("vector<T, N> WaveActive")
16803
0
SLANG_SPLICE(opName.hlslName
16804
0
)
16805
0
SLANG_RAW("(vector<T, N> expr)\n")
16806
0
SLANG_RAW("{\n")
16807
0
SLANG_RAW("    __target_switch\n")
16808
0
SLANG_RAW("    {\n")
16809
0
SLANG_RAW("    case glsl:\n")
16810
0
SLANG_RAW("    case wgsl:\n")
16811
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
16812
0
SLANG_SPLICE(opName.glslName
16813
0
)
16814
0
SLANG_RAW("\";\n")
16815
0
SLANG_RAW("    case hlsl:\n")
16816
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
16817
0
SLANG_SPLICE(opName.hlslName
16818
0
)
16819
0
SLANG_RAW("\";\n")
16820
0
SLANG_RAW("    case metal:\n")
16821
0
SLANG_RAW("        __intrinsic_asm \"simd_")
16822
0
SLANG_SPLICE(opName.metalName
16823
0
)
16824
0
SLANG_RAW("\";\n")
16825
0
SLANG_RAW("    case spirv:\n")
16826
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniform")
16827
0
SLANG_SPLICE(opName.spirvName
16828
0
)
16829
0
SLANG_RAW(" $$vector<T, N> result Subgroup Reduce $expr};\n")
16830
0
SLANG_RAW("    case cuda:\n")
16831
0
SLANG_RAW("        return WaveMask")
16832
0
SLANG_SPLICE(opName.hlslName
16833
0
)
16834
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16835
0
SLANG_RAW("    }\n")
16836
0
SLANG_RAW("}\n")
16837
0
SLANG_RAW("\n")
16838
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
16839
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16840
0
SLANG_RAW("matrix<T, N, M> WaveActive")
16841
0
SLANG_SPLICE(opName.hlslName
16842
0
)
16843
0
SLANG_RAW("(matrix<T, N, M> expr)\n")
16844
0
SLANG_RAW("{\n")
16845
0
SLANG_RAW("    __target_switch\n")
16846
0
SLANG_RAW("    {\n")
16847
0
SLANG_RAW("    case cuda:\n")
16848
0
SLANG_RAW("        return WaveMask")
16849
0
SLANG_SPLICE(opName.hlslName
16850
0
)
16851
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16852
0
SLANG_RAW("    case hlsl:\n")
16853
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
16854
0
SLANG_SPLICE(opName.hlslName
16855
0
)
16856
0
SLANG_RAW("\";\n")
16857
0
SLANG_RAW("    default:\n")
16858
0
SLANG_RAW("        matrix<T,N,M> result;\n")
16859
0
SLANG_RAW("        [ForceUnroll]\n")
16860
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
16861
0
SLANG_RAW("            result[i] = WaveActive")
16862
0
SLANG_SPLICE(opName.hlslName
16863
0
)
16864
0
SLANG_RAW("(expr[i]);\n")
16865
0
SLANG_RAW("        return result;\n")
16866
0
SLANG_RAW("    }\n")
16867
0
SLANG_RAW("}\n")
16868
16869
0
} // WaveActiveBitAnd, WaveActiveBitOr, WaveActiveBitXor
16870
0
SLANG_RAW("#line 15325 \"hlsl.meta.slang\"")
16871
0
SLANG_RAW("\n")
16872
0
SLANG_RAW("\n")
16873
0
SLANG_RAW("// WaveActiveMin/Max\n")
16874
16875
0
struct WaveActiveMinMaxEntry { const char* name; const char* metalName; };
16876
0
const WaveActiveMinMaxEntry kWaveActiveMinMaxNames[] = {{"Min", "min"}, {"Max", "max"}};
16877
0
for (const auto opName : kWaveActiveMinMaxNames) {
16878
0
SLANG_RAW("#line 15332 \"hlsl.meta.slang\"")
16879
0
SLANG_RAW("\n")
16880
0
SLANG_RAW("/// @category wave\n")
16881
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
16882
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
16883
0
SLANG_RAW("__spirv_version(1.3)\n")
16884
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16885
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16886
0
SLANG_RAW("T WaveActive")
16887
0
SLANG_SPLICE(opName.name
16888
0
)
16889
0
SLANG_RAW("(T expr)\n")
16890
0
SLANG_RAW("{\n")
16891
0
SLANG_RAW("    __target_switch\n")
16892
0
SLANG_RAW("    {\n")
16893
0
SLANG_RAW("    case glsl:\n")
16894
0
SLANG_RAW("    case wgsl:\n")
16895
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
16896
0
SLANG_SPLICE(opName.name
16897
0
)
16898
0
SLANG_RAW("\";\n")
16899
0
SLANG_RAW("    case hlsl:\n")
16900
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
16901
0
SLANG_SPLICE(opName.name
16902
0
)
16903
0
SLANG_RAW("\";\n")
16904
0
SLANG_RAW("    case metal:\n")
16905
0
SLANG_RAW("        __intrinsic_asm \"simd_")
16906
0
SLANG_SPLICE(opName.metalName
16907
0
)
16908
0
SLANG_RAW("\";\n")
16909
0
SLANG_RAW("    case spirv:\n")
16910
0
SLANG_RAW("        if (__isFloat<T>())\n")
16911
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformF")
16912
0
SLANG_SPLICE(opName.name
16913
0
)
16914
0
SLANG_RAW(" $$T result Subgroup Reduce $expr};\n")
16915
0
SLANG_RAW("        else if (__isUnsignedInt<T>())\n")
16916
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformU")
16917
0
SLANG_SPLICE(opName.name
16918
0
)
16919
0
SLANG_RAW(" $$T result Subgroup Reduce $expr};\n")
16920
0
SLANG_RAW("        else\n")
16921
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformS")
16922
0
SLANG_SPLICE(opName.name
16923
0
)
16924
0
SLANG_RAW(" $$T result Subgroup Reduce $expr};\n")
16925
0
SLANG_RAW("    case cuda:\n")
16926
0
SLANG_RAW("        return WaveMask")
16927
0
SLANG_SPLICE(opName.name
16928
0
)
16929
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16930
0
SLANG_RAW("    }\n")
16931
0
SLANG_RAW("}\n")
16932
0
SLANG_RAW("\n")
16933
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
16934
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
16935
0
SLANG_RAW("__spirv_version(1.3)\n")
16936
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
16937
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16938
0
SLANG_RAW("vector<T, N> WaveActive")
16939
0
SLANG_SPLICE(opName.name
16940
0
)
16941
0
SLANG_RAW("(vector<T, N> expr)\n")
16942
0
SLANG_RAW("{\n")
16943
0
SLANG_RAW("    __target_switch\n")
16944
0
SLANG_RAW("    {\n")
16945
0
SLANG_RAW("    case glsl:\n")
16946
0
SLANG_RAW("    case wgsl:\n")
16947
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
16948
0
SLANG_SPLICE(opName.name
16949
0
)
16950
0
SLANG_RAW("\";\n")
16951
0
SLANG_RAW("    case hlsl:\n")
16952
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
16953
0
SLANG_SPLICE(opName.name
16954
0
)
16955
0
SLANG_RAW("\";\n")
16956
0
SLANG_RAW("    case metal:\n")
16957
0
SLANG_RAW("        __intrinsic_asm \"simd_")
16958
0
SLANG_SPLICE(opName.metalName
16959
0
)
16960
0
SLANG_RAW("\";\n")
16961
0
SLANG_RAW("    case spirv:\n")
16962
0
SLANG_RAW("        if (__isFloat<T>())\n")
16963
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformF")
16964
0
SLANG_SPLICE(opName.name
16965
0
)
16966
0
SLANG_RAW(" $$vector<T, N> result Subgroup Reduce $expr};\n")
16967
0
SLANG_RAW("        else if (__isUnsignedInt<T>())\n")
16968
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformU")
16969
0
SLANG_SPLICE(opName.name
16970
0
)
16971
0
SLANG_RAW(" $$vector<T, N> result Subgroup Reduce $expr};\n")
16972
0
SLANG_RAW("        else\n")
16973
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformS")
16974
0
SLANG_SPLICE(opName.name
16975
0
)
16976
0
SLANG_RAW(" $$vector<T, N> result Subgroup Reduce $expr};\n")
16977
0
SLANG_RAW("    case cuda:\n")
16978
0
SLANG_RAW("        return WaveMask")
16979
0
SLANG_SPLICE(opName.name
16980
0
)
16981
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16982
0
SLANG_RAW("    }\n")
16983
0
SLANG_RAW("}\n")
16984
0
SLANG_RAW("\n")
16985
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
16986
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
16987
0
SLANG_RAW("matrix<T, N, M> WaveActive")
16988
0
SLANG_SPLICE(opName.name
16989
0
)
16990
0
SLANG_RAW("(matrix<T, N, M> expr)\n")
16991
0
SLANG_RAW("{\n")
16992
0
SLANG_RAW("    __target_switch\n")
16993
0
SLANG_RAW("    {\n")
16994
0
SLANG_RAW("    case cuda:\n")
16995
0
SLANG_RAW("        return WaveMask")
16996
0
SLANG_SPLICE(opName.name
16997
0
)
16998
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
16999
0
SLANG_RAW("    case hlsl:\n")
17000
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
17001
0
SLANG_SPLICE(opName.name
17002
0
)
17003
0
SLANG_RAW("\";\n")
17004
0
SLANG_RAW("    default:\n")
17005
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17006
0
SLANG_RAW("        [ForceUnroll]\n")
17007
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17008
0
SLANG_RAW("            result[i] = WaveActive")
17009
0
SLANG_SPLICE(opName.name
17010
0
)
17011
0
SLANG_RAW("(expr[i]);\n")
17012
0
SLANG_RAW("        return result;\n")
17013
0
SLANG_RAW("    }\n")
17014
0
SLANG_RAW("}\n")
17015
0
SLANG_RAW("\n")
17016
17017
0
} // WaveActiveMinMax.
17018
0
SLANG_RAW("#line 15411 \"hlsl.meta.slang\"")
17019
0
SLANG_RAW("\n")
17020
0
SLANG_RAW("\n")
17021
0
SLANG_RAW("// WaveActiveProduct/Sum\n")
17022
17023
0
struct WaveActiveProductSumEntry { const char* hlslName; const char* glslName; const char* metalName; };
17024
0
const WaveActiveProductSumEntry kWaveActivProductSumNames[] = {{"Product", "Mul", "product"}, {"Sum", "Add", "sum"}};
17025
0
for (auto opName : kWaveActivProductSumNames) {
17026
0
SLANG_RAW("#line 15418 \"hlsl.meta.slang\"")
17027
0
SLANG_RAW("\n")
17028
0
SLANG_RAW("/// @category wave\n")
17029
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
17030
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17031
0
SLANG_RAW("__spirv_version(1.3)\n")
17032
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17033
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17034
0
SLANG_RAW("T WaveActive")
17035
0
SLANG_SPLICE(opName.hlslName
17036
0
)
17037
0
SLANG_RAW("(T expr)\n")
17038
0
SLANG_RAW("{\n")
17039
0
SLANG_RAW("    __target_switch\n")
17040
0
SLANG_RAW("    {\n")
17041
0
SLANG_RAW("    case glsl:\n")
17042
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17043
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
17044
0
SLANG_SPLICE(opName.glslName
17045
0
)
17046
0
SLANG_RAW("($0)\";\n")
17047
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActive")
17048
0
SLANG_SPLICE(opName.hlslName
17049
0
)
17050
0
SLANG_RAW("\";\n")
17051
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_")
17052
0
SLANG_SPLICE(opName.metalName
17053
0
)
17054
0
SLANG_RAW("\";\n")
17055
0
SLANG_RAW("    case spirv:\n")
17056
0
SLANG_RAW("        if (__isFloat<T>())\n")
17057
0
SLANG_RAW("            return spirv_asm {\n")
17058
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17059
0
SLANG_RAW("                OpGroupNonUniformF")
17060
0
SLANG_SPLICE(opName.glslName
17061
0
)
17062
0
SLANG_RAW(" $$T result Subgroup 0 $expr\n")
17063
0
SLANG_RAW("            };\n")
17064
0
SLANG_RAW("        else if (__isInt<T>())\n")
17065
0
SLANG_RAW("        {\n")
17066
0
SLANG_RAW("            return spirv_asm\n")
17067
0
SLANG_RAW("            {\n")
17068
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17069
0
SLANG_RAW("                OpGroupNonUniformI")
17070
0
SLANG_SPLICE(opName.glslName
17071
0
)
17072
0
SLANG_RAW(" $$T result Subgroup 0 $expr;\n")
17073
0
SLANG_RAW("            };\n")
17074
0
SLANG_RAW("        }\n")
17075
0
SLANG_RAW("        else return expr;\n")
17076
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroup")
17077
0
SLANG_SPLICE(opName.glslName
17078
0
)
17079
0
SLANG_RAW("\";\n")
17080
0
SLANG_RAW("    case cuda:\n")
17081
0
SLANG_RAW("        return WaveMask")
17082
0
SLANG_SPLICE(opName.hlslName
17083
0
)
17084
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
17085
0
SLANG_RAW("    }\n")
17086
0
SLANG_RAW("}\n")
17087
0
SLANG_RAW("\n")
17088
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
17089
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17090
0
SLANG_RAW("__spirv_version(1.3)\n")
17091
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17092
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17093
0
SLANG_RAW("vector<T,N> WaveActive")
17094
0
SLANG_SPLICE(opName.hlslName
17095
0
)
17096
0
SLANG_RAW("(vector<T,N> expr)\n")
17097
0
SLANG_RAW("{\n")
17098
0
SLANG_RAW("    __target_switch\n")
17099
0
SLANG_RAW("    {\n")
17100
0
SLANG_RAW("    case glsl:\n")
17101
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17102
0
SLANG_RAW("        __intrinsic_asm \"subgroup")
17103
0
SLANG_SPLICE(opName.glslName
17104
0
)
17105
0
SLANG_RAW("($0)\";\n")
17106
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActive")
17107
0
SLANG_SPLICE(opName.hlslName
17108
0
)
17109
0
SLANG_RAW("\";\n")
17110
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_")
17111
0
SLANG_SPLICE(opName.metalName
17112
0
)
17113
0
SLANG_RAW("\";\n")
17114
0
SLANG_RAW("    case spirv:\n")
17115
0
SLANG_RAW("        if (__isFloat<T>())\n")
17116
0
SLANG_RAW("            return spirv_asm {\n")
17117
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17118
0
SLANG_RAW("                OpGroupNonUniformF")
17119
0
SLANG_SPLICE(opName.glslName
17120
0
)
17121
0
SLANG_RAW(" $$vector<T,N> result Subgroup 0 $expr\n")
17122
0
SLANG_RAW("            };\n")
17123
0
SLANG_RAW("        else if (__isInt<T>())\n")
17124
0
SLANG_RAW("        {\n")
17125
0
SLANG_RAW("            return spirv_asm\n")
17126
0
SLANG_RAW("            {\n")
17127
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17128
0
SLANG_RAW("                OpGroupNonUniformI")
17129
0
SLANG_SPLICE(opName.glslName
17130
0
)
17131
0
SLANG_RAW(" $$vector<T,N> result Subgroup 0 $expr;\n")
17132
0
SLANG_RAW("            };\n")
17133
0
SLANG_RAW("        }\n")
17134
0
SLANG_RAW("        else return expr;\n")
17135
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroup")
17136
0
SLANG_SPLICE(opName.glslName
17137
0
)
17138
0
SLANG_RAW("\";\n")
17139
0
SLANG_RAW("    case cuda:\n")
17140
0
SLANG_RAW("        return WaveMask")
17141
0
SLANG_SPLICE(opName.hlslName
17142
0
)
17143
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
17144
0
SLANG_RAW("    }\n")
17145
0
SLANG_RAW("}\n")
17146
0
SLANG_RAW("\n")
17147
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
17148
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17149
0
SLANG_RAW("matrix<T, N, M> WaveActive")
17150
0
SLANG_SPLICE(opName.hlslName
17151
0
)
17152
0
SLANG_RAW("(matrix<T, N, M> expr)\n")
17153
0
SLANG_RAW("{\n")
17154
0
SLANG_RAW("    __target_switch\n")
17155
0
SLANG_RAW("    {\n")
17156
0
SLANG_RAW("    case cuda:\n")
17157
0
SLANG_RAW("        return WaveMask")
17158
0
SLANG_SPLICE(opName.hlslName
17159
0
)
17160
0
SLANG_RAW("(WaveGetActiveMask(), expr);\n")
17161
0
SLANG_RAW("    case hlsl:\n")
17162
0
SLANG_RAW("        __intrinsic_asm \"WaveActive")
17163
0
SLANG_SPLICE(opName.hlslName
17164
0
)
17165
0
SLANG_RAW("\";\n")
17166
0
SLANG_RAW("    default:\n")
17167
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17168
0
SLANG_RAW("        [ForceUnroll]\n")
17169
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17170
0
SLANG_RAW("            result[i] = WaveActive")
17171
0
SLANG_SPLICE(opName.hlslName
17172
0
)
17173
0
SLANG_RAW("(expr[i]);\n")
17174
0
SLANG_RAW("        return result;\n")
17175
0
SLANG_RAW("    }\n")
17176
0
SLANG_RAW("}\n")
17177
17178
0
} // WaveActiveProduct/WaveActiveProductSum.
17179
0
SLANG_RAW("#line 15510 \"hlsl.meta.slang\"")
17180
0
SLANG_RAW("\n")
17181
0
SLANG_RAW("\n")
17182
0
SLANG_RAW("/// @category wave\n")
17183
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17184
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
17185
0
SLANG_RAW("__spirv_version(1.3)\n")
17186
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
17187
0
SLANG_RAW("bool WaveActiveAllEqual(T value)\n")
17188
0
SLANG_RAW("{\n")
17189
0
SLANG_RAW("    __target_switch\n")
17190
0
SLANG_RAW("    {\n")
17191
0
SLANG_RAW("    case glsl:\n")
17192
0
SLANG_RAW("        __intrinsic_asm \"subgroupAllEqual($0)\";\n")
17193
0
SLANG_RAW("    case hlsl:\n")
17194
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllEqual\";\n")
17195
0
SLANG_RAW("    case spirv:\n")
17196
0
SLANG_RAW("        return spirv_asm\n")
17197
0
SLANG_RAW("        {\n")
17198
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
17199
0
SLANG_RAW("            OpGroupNonUniformAllEqual $$bool result Subgroup $value\n")
17200
0
SLANG_RAW("        };\n")
17201
0
SLANG_RAW("    default:\n")
17202
0
SLANG_RAW("        return WaveMaskAllEqual(WaveGetActiveMask(), value);\n")
17203
0
SLANG_RAW("    }\n")
17204
0
SLANG_RAW("}\n")
17205
0
SLANG_RAW("\n")
17206
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17207
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
17208
0
SLANG_RAW("__spirv_version(1.3)\n")
17209
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_vote)]\n")
17210
0
SLANG_RAW("bool WaveActiveAllEqual(vector<T,N> value)\n")
17211
0
SLANG_RAW("{\n")
17212
0
SLANG_RAW("    __target_switch\n")
17213
0
SLANG_RAW("    {\n")
17214
0
SLANG_RAW("    case glsl:\n")
17215
0
SLANG_RAW("        __intrinsic_asm \"subgroupAllEqual($0)\";\n")
17216
0
SLANG_RAW("    case hlsl:\n")
17217
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllEqual\";\n")
17218
0
SLANG_RAW("    case spirv:\n")
17219
0
SLANG_RAW("        return spirv_asm\n")
17220
0
SLANG_RAW("        {\n")
17221
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
17222
0
SLANG_RAW("            OpGroupNonUniformAllEqual $$bool result Subgroup $value\n")
17223
0
SLANG_RAW("        };\n")
17224
0
SLANG_RAW("    default:\n")
17225
0
SLANG_RAW("        return WaveMaskAllEqual(WaveGetActiveMask(), value);\n")
17226
0
SLANG_RAW("    }\n")
17227
0
SLANG_RAW("}\n")
17228
0
SLANG_RAW("\n")
17229
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17230
0
SLANG_RAW("[require(cuda_hlsl, subgroup_vote)]\n")
17231
0
SLANG_RAW("bool WaveActiveAllEqual(matrix<T, N, M> value)\n")
17232
0
SLANG_RAW("{\n")
17233
0
SLANG_RAW("    __target_switch\n")
17234
0
SLANG_RAW("    {\n")
17235
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActiveAllEqual\";\n")
17236
0
SLANG_RAW("    default:\n")
17237
0
SLANG_RAW("        return WaveMaskAllEqual(WaveGetActiveMask(), value);\n")
17238
0
SLANG_RAW("    }\n")
17239
0
SLANG_RAW("}\n")
17240
0
SLANG_RAW("\n")
17241
0
SLANG_RAW("/// @category wave\n")
17242
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
17243
0
SLANG_RAW("__spirv_version(1.3)\n")
17244
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17245
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_vote)]\n")
17246
0
SLANG_RAW("bool WaveActiveAllTrue(bool condition)\n")
17247
0
SLANG_RAW("{\n")
17248
0
SLANG_RAW("    __target_switch\n")
17249
0
SLANG_RAW("    {\n")
17250
0
SLANG_RAW("    case glsl:\n")
17251
0
SLANG_RAW("    case wgsl:\n")
17252
0
SLANG_RAW("        __intrinsic_asm \"subgroupAll\";\n")
17253
0
SLANG_RAW("    case hlsl:\n")
17254
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAllTrue($0)\";\n")
17255
0
SLANG_RAW("    case metal:\n")
17256
0
SLANG_RAW("        __intrinsic_asm \"simd_all\";\n")
17257
0
SLANG_RAW("    case spirv:\n")
17258
0
SLANG_RAW("        return spirv_asm\n")
17259
0
SLANG_RAW("        {\n")
17260
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
17261
0
SLANG_RAW("            OpGroupNonUniformAll $$bool result Subgroup $condition\n")
17262
0
SLANG_RAW("        };\n")
17263
0
SLANG_RAW("    case cuda:\n")
17264
0
SLANG_RAW("        return WaveMaskAllTrue(WaveGetActiveMask(), condition);\n")
17265
0
SLANG_RAW("    }\n")
17266
0
SLANG_RAW("}\n")
17267
0
SLANG_RAW("\n")
17268
0
SLANG_RAW("/// @category wave\n")
17269
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
17270
0
SLANG_RAW("__spirv_version(1.3)\n")
17271
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17272
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_vote)]\n")
17273
0
SLANG_RAW("bool WaveActiveAnyTrue(bool condition)\n")
17274
0
SLANG_RAW("{\n")
17275
0
SLANG_RAW("    __target_switch\n")
17276
0
SLANG_RAW("    {\n")
17277
0
SLANG_RAW("    case glsl:\n")
17278
0
SLANG_RAW("    case wgsl:\n")
17279
0
SLANG_RAW("        __intrinsic_asm \"subgroupAny\";\n")
17280
0
SLANG_RAW("    case hlsl:\n")
17281
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveAnyTrue($0)\";\n")
17282
0
SLANG_RAW("    case metal:\n")
17283
0
SLANG_RAW("        __intrinsic_asm \"simd_any\";\n")
17284
0
SLANG_RAW("    case spirv:\n")
17285
0
SLANG_RAW("        return spirv_asm\n")
17286
0
SLANG_RAW("        {\n")
17287
0
SLANG_RAW("            OpCapability GroupNonUniformVote;\n")
17288
0
SLANG_RAW("            OpGroupNonUniformAny $$bool result Subgroup $condition\n")
17289
0
SLANG_RAW("        };\n")
17290
0
SLANG_RAW("    default:\n")
17291
0
SLANG_RAW("        return WaveMaskAnyTrue(WaveGetActiveMask(), condition);\n")
17292
0
SLANG_RAW("    }\n")
17293
0
SLANG_RAW("}\n")
17294
0
SLANG_RAW("\n")
17295
0
SLANG_RAW("\n")
17296
0
SLANG_RAW("//@hidden:\n")
17297
0
SLANG_RAW("[ForceInline]\n")
17298
0
SLANG_RAW("uint64_t __metal_simd_ballot(bool expr)\n")
17299
0
SLANG_RAW("{\n")
17300
0
SLANG_RAW("    __intrinsic_asm \"uint64_t(simd_ballot($0))\";\n")
17301
0
SLANG_RAW("}\n")
17302
0
SLANG_RAW("\n")
17303
0
SLANG_RAW("[ForceInline]\n")
17304
0
SLANG_RAW("uint4 __metal_simd_vote_mask_to_uint4(uint64_t mask)\n")
17305
0
SLANG_RAW("{\n")
17306
0
SLANG_RAW("    return uint4(uint(mask & 0xFFFFFFFF), uint(mask >> 32), 0, 0);\n")
17307
0
SLANG_RAW("}\n")
17308
0
SLANG_RAW("\n")
17309
0
SLANG_RAW("//@public:\n")
17310
0
SLANG_RAW("\n")
17311
0
SLANG_RAW("/// @category wave\n")
17312
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17313
0
SLANG_RAW("__spirv_version(1.3)\n")
17314
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17315
0
SLANG_RAW("[NonUniformReturn]\n")
17316
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17317
0
SLANG_RAW("uint4 WaveActiveBallot(bool condition)\n")
17318
0
SLANG_RAW("{\n")
17319
0
SLANG_RAW("    __target_switch\n")
17320
0
SLANG_RAW("    {\n")
17321
0
SLANG_RAW("    case glsl:\n")
17322
0
SLANG_RAW("    case wgsl:\n")
17323
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallot\";\n")
17324
0
SLANG_RAW("    case hlsl:\n")
17325
0
SLANG_RAW("        __intrinsic_asm \"WaveActiveBallot\";\n")
17326
0
SLANG_RAW("    case metal: return __metal_simd_vote_mask_to_uint4(__metal_simd_ballot(condition));\n")
17327
0
SLANG_RAW("    case spirv:\n")
17328
0
SLANG_RAW("        return spirv_asm\n")
17329
0
SLANG_RAW("        {\n")
17330
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
17331
0
SLANG_RAW("            OpGroupNonUniformBallot $$uint4 result Subgroup $condition\n")
17332
0
SLANG_RAW("        };\n")
17333
0
SLANG_RAW("    default:\n")
17334
0
SLANG_RAW("        return WaveMaskBallot(WaveGetActiveMask(), condition);\n")
17335
0
SLANG_RAW("    }\n")
17336
0
SLANG_RAW("}\n")
17337
0
SLANG_RAW("\n")
17338
0
SLANG_RAW("/// @category wave\n")
17339
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, subgroup_basic_ballot)]\n")
17340
0
SLANG_RAW("uint WaveActiveCountBits(bool value)\n")
17341
0
SLANG_RAW("{\n")
17342
0
SLANG_RAW("    __target_switch\n")
17343
0
SLANG_RAW("    {\n")
17344
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActiveCountBits\";\n")
17345
0
SLANG_RAW("    case glsl:\n")
17346
0
SLANG_RAW("    case spirv:\n")
17347
0
SLANG_RAW("    case metal:\n")
17348
0
SLANG_RAW("        return _WaveCountBits(WaveActiveBallot(value));\n")
17349
0
SLANG_RAW("    default:\n")
17350
0
SLANG_RAW("        return WaveMaskCountBits(WaveGetActiveMask(), value);\n")
17351
0
SLANG_RAW("    }\n")
17352
0
SLANG_RAW("}\n")
17353
0
SLANG_RAW("\n")
17354
0
SLANG_RAW("/// @category wave\n")
17355
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_basic)\n")
17356
0
SLANG_RAW("__spirv_version(1.3)\n")
17357
0
SLANG_RAW("[NonUniformReturn]\n")
17358
0
SLANG_RAW("[ForceInline]\n")
17359
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_basic)]\n")
17360
0
SLANG_RAW("uint WaveGetLaneCount()\n")
17361
0
SLANG_RAW("{\n")
17362
0
SLANG_RAW("    __target_switch\n")
17363
0
SLANG_RAW("    {\n")
17364
0
SLANG_RAW("    case glsl: __intrinsic_asm  \"(gl_SubgroupSize)\";\n")
17365
0
SLANG_RAW("    case cuda: __intrinsic_asm  \"(warpSize)\";\n")
17366
0
SLANG_RAW("    case hlsl: __intrinsic_asm  \"WaveGetLaneCount()\";\n")
17367
0
SLANG_RAW("    case spirv:\n")
17368
0
SLANG_RAW("        return spirv_asm\n")
17369
0
SLANG_RAW("        {\n")
17370
0
SLANG_RAW("            OpCapability GroupNonUniform;\n")
17371
0
SLANG_RAW("            result:$$uint = OpLoad builtin(SubgroupSize:uint)\n")
17372
0
SLANG_RAW("        };\n")
17373
0
SLANG_RAW("    case metal:\n")
17374
0
SLANG_RAW("        return __builtinWaveLaneCount;\n")
17375
0
SLANG_RAW("    case wgsl:\n")
17376
0
SLANG_RAW("        __requireTargetExtension(\"subgroups\");\n")
17377
0
SLANG_RAW("        return __builtinWaveLaneCount;\n")
17378
0
SLANG_RAW("    }\n")
17379
0
SLANG_RAW("}\n")
17380
0
SLANG_RAW("\n")
17381
0
SLANG_RAW("/// @category wave\n")
17382
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_basic)\n")
17383
0
SLANG_RAW("__spirv_version(1.3)\n")
17384
0
SLANG_RAW("[NonUniformReturn]\n")
17385
0
SLANG_RAW("[ForceInline]\n")
17386
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_basic)]\n")
17387
0
SLANG_RAW("uint WaveGetLaneIndex()\n")
17388
0
SLANG_RAW("{\n")
17389
0
SLANG_RAW("    __target_switch\n")
17390
0
SLANG_RAW("    {\n")
17391
0
SLANG_RAW("    case glsl: __intrinsic_asm  \"(gl_SubgroupInvocationID)\";\n")
17392
0
SLANG_RAW("    case cuda: __intrinsic_asm  \"_getLaneId()\";\n")
17393
0
SLANG_RAW("    case hlsl: __intrinsic_asm  \"WaveGetLaneIndex()\";\n")
17394
0
SLANG_RAW("    case spirv:\n")
17395
0
SLANG_RAW("        return spirv_asm\n")
17396
0
SLANG_RAW("        {\n")
17397
0
SLANG_RAW("            OpCapability GroupNonUniform;\n")
17398
0
SLANG_RAW("            result:$$uint = OpLoad builtin(SubgroupLocalInvocationId:uint)\n")
17399
0
SLANG_RAW("        };\n")
17400
0
SLANG_RAW("    case metal:\n")
17401
0
SLANG_RAW("        return __builtinWaveLaneIndex;\n")
17402
0
SLANG_RAW("    case wgsl:\n")
17403
0
SLANG_RAW("        __requireTargetExtension(\"subgroups\");\n")
17404
0
SLANG_RAW("        return __builtinWaveLaneIndex;\n")
17405
0
SLANG_RAW("    }\n")
17406
0
SLANG_RAW("}\n")
17407
0
SLANG_RAW("\n")
17408
0
SLANG_RAW("/// @category wave\n")
17409
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_basic)\n")
17410
0
SLANG_RAW("__spirv_version(1.3)\n")
17411
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17412
0
SLANG_RAW("[NonUniformReturn]\n")
17413
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_basic)]\n")
17414
0
SLANG_RAW("bool WaveIsFirstLane()\n")
17415
0
SLANG_RAW("{\n")
17416
0
SLANG_RAW("    __target_switch\n")
17417
0
SLANG_RAW("    {\n")
17418
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupElect()\";\n")
17419
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveIsFirstLane()\";\n")
17420
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_is_first\";\n")
17421
0
SLANG_RAW("    case spirv:\n")
17422
0
SLANG_RAW("        return spirv_asm\n")
17423
0
SLANG_RAW("        {\n")
17424
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
17425
0
SLANG_RAW("            OpGroupNonUniformElect $$bool result Subgroup\n")
17426
0
SLANG_RAW("        };\n")
17427
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupElect\";\n")
17428
0
SLANG_RAW("    case cuda:\n")
17429
0
SLANG_RAW("        return WaveMaskIsFirstLane(WaveGetActiveMask());\n")
17430
0
SLANG_RAW("    }\n")
17431
0
SLANG_RAW("}\n")
17432
0
SLANG_RAW("\n")
17433
0
SLANG_RAW("// It's useful to have a wave uint4 version of countbits, because some wave functions return uint4.\n")
17434
0
SLANG_RAW("// This implementation tries to limit the amount of work required by the actual lane count.\n")
17435
0
SLANG_RAW("/// @category wave\n")
17436
0
SLANG_RAW("__spirv_version(1.3)\n")
17437
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv, subgroup_basic_ballot)]\n")
17438
0
SLANG_RAW("uint _WaveCountBits(uint4 value)\n")
17439
0
SLANG_RAW("{\n")
17440
0
SLANG_RAW("    __target_switch\n")
17441
0
SLANG_RAW("    {\n")
17442
0
SLANG_RAW("    case spirv:\n")
17443
0
SLANG_RAW("        return spirv_asm\n")
17444
0
SLANG_RAW("        {\n")
17445
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
17446
0
SLANG_RAW("            OpGroupNonUniformBallotBitCount $$uint result Subgroup Reduce $value\n")
17447
0
SLANG_RAW("        };\n")
17448
0
SLANG_RAW("    default:\n")
17449
0
SLANG_RAW("        // Assume since WaveGetLaneCount should be known at compile time, the branches will hopefully boil away\n")
17450
0
SLANG_RAW("        const uint waveLaneCount = WaveGetLaneCount();\n")
17451
0
SLANG_RAW("        switch ((waveLaneCount - 1) / 32)\n")
17452
0
SLANG_RAW("        {\n")
17453
0
SLANG_RAW("            default:\n")
17454
0
SLANG_RAW("            case 0: return countbits(value.x);\n")
17455
0
SLANG_RAW("            case 1: return countbits(value.x) + countbits(value.y);\n")
17456
0
SLANG_RAW("            case 2: return countbits(value.x) + countbits(value.y) + countbits(value.z);\n")
17457
0
SLANG_RAW("            case 3: return countbits(value.x) + countbits(value.y) + countbits(value.z) + countbits(value.w);\n")
17458
0
SLANG_RAW("        }\n")
17459
0
SLANG_RAW("    }\n")
17460
0
SLANG_RAW("}\n")
17461
0
SLANG_RAW("\n")
17462
0
SLANG_RAW("// Prefix\n")
17463
0
SLANG_RAW("/// @category wave\n")
17464
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
17465
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17466
0
SLANG_RAW("__spirv_version(1.3)\n")
17467
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17468
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17469
0
SLANG_RAW("T WavePrefixProduct(T expr)\n")
17470
0
SLANG_RAW("{\n")
17471
0
SLANG_RAW("    __target_switch\n")
17472
0
SLANG_RAW("    {\n")
17473
0
SLANG_RAW("    case glsl:\n")
17474
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17475
0
SLANG_RAW("        __intrinsic_asm \"subgroupExclusiveMul($0)\";\n")
17476
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixProduct\";\n")
17477
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_prefix_exclusive_product\";\n")
17478
0
SLANG_RAW("    case spirv:\n")
17479
0
SLANG_RAW("        if (__isFloat<T>())\n")
17480
0
SLANG_RAW("            return spirv_asm {\n")
17481
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17482
0
SLANG_RAW("                OpGroupNonUniformFMul $$T result Subgroup ExclusiveScan $expr\n")
17483
0
SLANG_RAW("            };\n")
17484
0
SLANG_RAW("        else if (__isInt<T>())\n")
17485
0
SLANG_RAW("        {\n")
17486
0
SLANG_RAW("            return spirv_asm\n")
17487
0
SLANG_RAW("            {\n")
17488
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17489
0
SLANG_RAW("                OpGroupNonUniformIMul $$T result Subgroup ExclusiveScan $expr;\n")
17490
0
SLANG_RAW("            };\n")
17491
0
SLANG_RAW("        }\n")
17492
0
SLANG_RAW("        else return expr;\n")
17493
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupExclusiveMul\";\n")
17494
0
SLANG_RAW("    case cuda:\n")
17495
0
SLANG_RAW("        return WaveMaskPrefixProduct(WaveGetActiveMask(), expr);\n")
17496
0
SLANG_RAW("    }\n")
17497
0
SLANG_RAW("}\n")
17498
0
SLANG_RAW("\n")
17499
0
SLANG_RAW("/// @category wave\n")
17500
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
17501
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17502
0
SLANG_RAW("__spirv_version(1.3)\n")
17503
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17504
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17505
0
SLANG_RAW("vector<T,N> WavePrefixProduct(vector<T,N> expr)\n")
17506
0
SLANG_RAW("{\n")
17507
0
SLANG_RAW("    __target_switch\n")
17508
0
SLANG_RAW("    {\n")
17509
0
SLANG_RAW("    case glsl:\n")
17510
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17511
0
SLANG_RAW("        __intrinsic_asm \"subgroupExclusiveMul($0)\";\n")
17512
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixProduct\";\n")
17513
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_prefix_exclusive_product\";\n")
17514
0
SLANG_RAW("    case spirv:\n")
17515
0
SLANG_RAW("        if (__isFloat<T>())\n")
17516
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformFMul $$vector<T,N> result Subgroup ExclusiveScan $expr};\n")
17517
0
SLANG_RAW("        else if (__isInt<T>())\n")
17518
0
SLANG_RAW("        {\n")
17519
0
SLANG_RAW("            return spirv_asm\n")
17520
0
SLANG_RAW("            {\n")
17521
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17522
0
SLANG_RAW("                OpGroupNonUniformIMul $$vector<T,N> result Subgroup ExclusiveScan $expr;\n")
17523
0
SLANG_RAW("            };\n")
17524
0
SLANG_RAW("        }\n")
17525
0
SLANG_RAW("        else return expr;\n")
17526
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupExclusiveMul\";\n")
17527
0
SLANG_RAW("    case cuda:\n")
17528
0
SLANG_RAW("        return WaveMaskPrefixProduct(WaveGetActiveMask(), expr);\n")
17529
0
SLANG_RAW("    }\n")
17530
0
SLANG_RAW("}\n")
17531
0
SLANG_RAW("/// @category wave\n")
17532
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
17533
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv_wgsl, subgroup_arithmetic)]\n")
17534
0
SLANG_RAW("matrix<T, N, M> WavePrefixProduct(matrix<T, N, M> expr)\n")
17535
0
SLANG_RAW("{\n")
17536
0
SLANG_RAW("    __target_switch\n")
17537
0
SLANG_RAW("    {\n")
17538
0
SLANG_RAW("    case cuda:\n")
17539
0
SLANG_RAW("        return WaveMaskPrefixProduct(WaveGetActiveMask(), expr);\n")
17540
0
SLANG_RAW("    case hlsl:\n")
17541
0
SLANG_RAW("        __intrinsic_asm \"WavePrefixProduct\";\n")
17542
0
SLANG_RAW("    default:\n")
17543
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17544
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17545
0
SLANG_RAW("            result[i] = WavePrefixProduct(expr[i]);\n")
17546
0
SLANG_RAW("        return result;\n")
17547
0
SLANG_RAW("    }\n")
17548
0
SLANG_RAW("}\n")
17549
0
SLANG_RAW("\n")
17550
0
SLANG_RAW("/// @category wave\n")
17551
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
17552
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17553
0
SLANG_RAW("__spirv_version(1.3)\n")
17554
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17555
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17556
0
SLANG_RAW("T WavePrefixSum(T expr)\n")
17557
0
SLANG_RAW("{\n")
17558
0
SLANG_RAW("    __target_switch\n")
17559
0
SLANG_RAW("    {\n")
17560
0
SLANG_RAW("    case glsl:\n")
17561
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17562
0
SLANG_RAW("        __intrinsic_asm \"subgroupExclusiveAdd($0)\";\n")
17563
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixSum\";\n")
17564
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_prefix_exclusive_sum\";\n")
17565
0
SLANG_RAW("    case spirv:\n")
17566
0
SLANG_RAW("        if (__isFloat<T>())\n")
17567
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformFAdd $$T result Subgroup ExclusiveScan $expr};\n")
17568
0
SLANG_RAW("        else if (__isInt<T>())\n")
17569
0
SLANG_RAW("        {\n")
17570
0
SLANG_RAW("            return spirv_asm\n")
17571
0
SLANG_RAW("            {\n")
17572
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17573
0
SLANG_RAW("                result:$$T = OpGroupNonUniformIAdd Subgroup ExclusiveScan $expr;\n")
17574
0
SLANG_RAW("            };\n")
17575
0
SLANG_RAW("        }\n")
17576
0
SLANG_RAW("        else return expr;\n")
17577
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupExclusiveAdd\";\n")
17578
0
SLANG_RAW("    case cuda:\n")
17579
0
SLANG_RAW("        return WaveMaskPrefixSum(WaveGetActiveMask(), expr);\n")
17580
0
SLANG_RAW("    }\n")
17581
0
SLANG_RAW("}\n")
17582
0
SLANG_RAW("\n")
17583
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
17584
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_arithmetic)\n")
17585
0
SLANG_RAW("__spirv_version(1.3)\n")
17586
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17587
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17588
0
SLANG_RAW("vector<T,N> WavePrefixSum(vector<T,N> expr)\n")
17589
0
SLANG_RAW("{\n")
17590
0
SLANG_RAW("    __target_switch\n")
17591
0
SLANG_RAW("    {\n")
17592
0
SLANG_RAW("    case glsl:\n")
17593
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17594
0
SLANG_RAW("        __intrinsic_asm \"subgroupExclusiveAdd($0)\";\n")
17595
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixSum\";\n")
17596
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_prefix_exclusive_sum\";\n")
17597
0
SLANG_RAW("    case spirv:\n")
17598
0
SLANG_RAW("        if (__isFloat<T>())\n")
17599
0
SLANG_RAW("            return spirv_asm {OpCapability GroupNonUniformArithmetic; OpGroupNonUniformFAdd $$vector<T,N> result Subgroup ExclusiveScan $expr};\n")
17600
0
SLANG_RAW("        else if (__isInt<T>())\n")
17601
0
SLANG_RAW("        {\n")
17602
0
SLANG_RAW("            return spirv_asm\n")
17603
0
SLANG_RAW("            {\n")
17604
0
SLANG_RAW("                OpCapability GroupNonUniformArithmetic;\n")
17605
0
SLANG_RAW("                result:$$vector<T,N> = OpGroupNonUniformIAdd Subgroup ExclusiveScan $expr;\n")
17606
0
SLANG_RAW("            };\n")
17607
0
SLANG_RAW("        }\n")
17608
0
SLANG_RAW("        else return expr;\n")
17609
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupExclusiveAdd\";\n")
17610
0
SLANG_RAW("    case cuda:\n")
17611
0
SLANG_RAW("        return WaveMaskPrefixSum(WaveGetActiveMask(), expr);\n")
17612
0
SLANG_RAW("    }\n")
17613
0
SLANG_RAW("}\n")
17614
0
SLANG_RAW("\n")
17615
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
17616
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_arithmetic)]\n")
17617
0
SLANG_RAW("matrix<T,N,M> WavePrefixSum(matrix<T,N,M> expr)\n")
17618
0
SLANG_RAW("{\n")
17619
0
SLANG_RAW("    __target_switch\n")
17620
0
SLANG_RAW("    {\n")
17621
0
SLANG_RAW("    case cuda:\n")
17622
0
SLANG_RAW("        return WaveMaskPrefixSum(WaveGetActiveMask(), expr);\n")
17623
0
SLANG_RAW("    case hlsl:\n")
17624
0
SLANG_RAW("        __intrinsic_asm \"WavePrefixSum\";\n")
17625
0
SLANG_RAW("    default:\n")
17626
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17627
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17628
0
SLANG_RAW("            result[i] = WavePrefixSum(expr[i]);\n")
17629
0
SLANG_RAW("        return result;\n")
17630
0
SLANG_RAW("    }\n")
17631
0
SLANG_RAW("}\n")
17632
0
SLANG_RAW("\n")
17633
0
SLANG_RAW("/// @category wave\n")
17634
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17635
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17636
0
SLANG_RAW("__spirv_version(1.3)\n")
17637
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17638
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17639
0
SLANG_RAW("T WaveReadLaneFirst(T expr)\n")
17640
0
SLANG_RAW("{\n")
17641
0
SLANG_RAW("    __target_switch\n")
17642
0
SLANG_RAW("    {\n")
17643
0
SLANG_RAW("    case glsl:\n")
17644
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17645
0
SLANG_RAW("        __intrinsic_asm \"subgroupBroadcastFirst($0)\";\n")
17646
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneFirst\";\n")
17647
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_broadcast_first\";\n")
17648
0
SLANG_RAW("    case spirv:\n")
17649
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcastFirst $$T result Subgroup $expr};\n")
17650
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupBroadcastFirst\";\n")
17651
0
SLANG_RAW("    case cuda:\n")
17652
0
SLANG_RAW("        return WaveMaskReadLaneFirst(WaveGetActiveMask(), expr);\n")
17653
0
SLANG_RAW("    }\n")
17654
0
SLANG_RAW("}\n")
17655
0
SLANG_RAW("\n")
17656
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17657
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17658
0
SLANG_RAW("__spirv_version(1.3)\n")
17659
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17660
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17661
0
SLANG_RAW("vector<T,N> WaveReadLaneFirst(vector<T,N> expr)\n")
17662
0
SLANG_RAW("{\n")
17663
0
SLANG_RAW("    __target_switch\n")
17664
0
SLANG_RAW("    {\n")
17665
0
SLANG_RAW("    case glsl:\n")
17666
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17667
0
SLANG_RAW("        __intrinsic_asm \"subgroupBroadcastFirst($0)\";\n")
17668
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneFirst\";\n")
17669
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_broadcast_first\";\n")
17670
0
SLANG_RAW("    case spirv:\n")
17671
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcastFirst $$vector<T,N> result Subgroup $expr};\n")
17672
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupBroadcastFirst\";\n")
17673
0
SLANG_RAW("    case cuda:\n")
17674
0
SLANG_RAW("        return WaveMaskReadLaneFirst(WaveGetActiveMask(), expr);\n")
17675
0
SLANG_RAW("    }\n")
17676
0
SLANG_RAW("}\n")
17677
0
SLANG_RAW("\n")
17678
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17679
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17680
0
SLANG_RAW("matrix<T,N,M> WaveReadLaneFirst(matrix<T,N,M> expr)\n")
17681
0
SLANG_RAW("{\n")
17682
0
SLANG_RAW("    __target_switch\n")
17683
0
SLANG_RAW("    {\n")
17684
0
SLANG_RAW("    case cuda:\n")
17685
0
SLANG_RAW("        return WaveMaskReadLaneFirst(WaveGetActiveMask(), expr);\n")
17686
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneFirst\";\n")
17687
0
SLANG_RAW("    default:\n")
17688
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17689
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17690
0
SLANG_RAW("            result[i] = WaveReadLaneFirst(expr[i]);\n")
17691
0
SLANG_RAW("        return result;\n")
17692
0
SLANG_RAW("    }\n")
17693
0
SLANG_RAW("}\n")
17694
0
SLANG_RAW("\n")
17695
0
SLANG_RAW("// NOTE! WaveBroadcastLaneAt is *NOT* standard HLSL\n")
17696
0
SLANG_RAW("// It is provided as access to subgroupBroadcast which can only take a\n")
17697
0
SLANG_RAW("// constexpr laneId.\n")
17698
0
SLANG_RAW("// https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_shader_subgroup.txt\n")
17699
0
SLANG_RAW("// Versions SPIR-V greater than 1.4 loosen this restriction, and allow 'dynamic uniform' index\n")
17700
0
SLANG_RAW("// If that's the behavior required then client code should use WaveReadLaneAt which works this way.\n")
17701
0
SLANG_RAW("/// @category wave\n")
17702
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17703
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17704
0
SLANG_RAW("__spirv_version(1.3)\n")
17705
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17706
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17707
0
SLANG_RAW("T WaveBroadcastLaneAt(T value, constexpr int lane)\n")
17708
0
SLANG_RAW("{\n")
17709
0
SLANG_RAW("    __target_switch\n")
17710
0
SLANG_RAW("    {\n")
17711
0
SLANG_RAW("    case glsl:\n")
17712
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17713
0
SLANG_RAW("        __intrinsic_asm \"subgroupBroadcast($0, $1)\";\n")
17714
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17715
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_broadcast($0, ushort($1))\";\n")
17716
0
SLANG_RAW("    case spirv:\n")
17717
0
SLANG_RAW("        let ulane = uint(lane);\n")
17718
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcast $$T result Subgroup $value $ulane};\n")
17719
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupBroadcast\";\n")
17720
0
SLANG_RAW("    case cuda:\n")
17721
0
SLANG_RAW("        return WaveMaskBroadcastLaneAt(WaveGetActiveMask(), value, lane);\n")
17722
0
SLANG_RAW("    }\n")
17723
0
SLANG_RAW("}\n")
17724
0
SLANG_RAW("\n")
17725
0
SLANG_RAW("/// @category wave\n")
17726
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17727
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17728
0
SLANG_RAW("__spirv_version(1.3)\n")
17729
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17730
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17731
0
SLANG_RAW("vector<T,N> WaveBroadcastLaneAt(vector<T,N> value, constexpr int lane)\n")
17732
0
SLANG_RAW("{\n")
17733
0
SLANG_RAW("    __target_switch\n")
17734
0
SLANG_RAW("    {\n")
17735
0
SLANG_RAW("    case glsl:\n")
17736
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17737
0
SLANG_RAW("        __intrinsic_asm \"subgroupBroadcast($0, $1)\";\n")
17738
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17739
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_broadcast($0, ushort($1))\";\n")
17740
0
SLANG_RAW("    case spirv:\n")
17741
0
SLANG_RAW("        let ulane = uint(lane);\n")
17742
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformBallot; OpGroupNonUniformBroadcast $$vector<T,N> result Subgroup $value $ulane};\n")
17743
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupBroadcast\";\n")
17744
0
SLANG_RAW("    case cuda:\n")
17745
0
SLANG_RAW("        return WaveMaskBroadcastLaneAt(WaveGetActiveMask(), value, lane);\n")
17746
0
SLANG_RAW("    }\n")
17747
0
SLANG_RAW("}\n")
17748
0
SLANG_RAW("\n")
17749
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17750
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17751
0
SLANG_RAW("matrix<T, N, M> WaveBroadcastLaneAt(matrix<T, N, M> value, constexpr int lane)\n")
17752
0
SLANG_RAW("{\n")
17753
0
SLANG_RAW("    __target_switch\n")
17754
0
SLANG_RAW("    {\n")
17755
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple(_getActiveMask(), $0, $1)\";\n")
17756
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17757
0
SLANG_RAW("    default:\n")
17758
0
SLANG_RAW("        matrix<T, N, M> result;\n")
17759
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17760
0
SLANG_RAW("            result[i] = WaveBroadcastLaneAt(value[i], lane);\n")
17761
0
SLANG_RAW("        return result;\n")
17762
0
SLANG_RAW("    }\n")
17763
0
SLANG_RAW("}\n")
17764
0
SLANG_RAW("\n")
17765
0
SLANG_RAW("// TODO(JS): If it can be determines that the `laneId` is constExpr, then subgroupBroadcast\n")
17766
0
SLANG_RAW("// could be used on GLSL. For now we just use subgroupShuffle\n")
17767
0
SLANG_RAW("/// @category wave\n")
17768
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17769
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
17770
0
SLANG_RAW("__spirv_version(1.3)\n")
17771
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17772
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_shuffle)]\n")
17773
0
SLANG_RAW("T WaveReadLaneAt(T value, int lane)\n")
17774
0
SLANG_RAW("{\n")
17775
0
SLANG_RAW("    __target_switch\n")
17776
0
SLANG_RAW("    {\n")
17777
0
SLANG_RAW("    case glsl:\n")
17778
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17779
0
SLANG_RAW("        __intrinsic_asm \"subgroupShuffle($0, $1)\";\n")
17780
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17781
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_shuffle($0, ushort($1))\";\n")
17782
0
SLANG_RAW("    case spirv:\n")
17783
0
SLANG_RAW("        let ulane = uint(lane);\n")
17784
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformShuffle; OpGroupNonUniformShuffle $$T result Subgroup $value $ulane};\n")
17785
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupShuffle\";\n")
17786
0
SLANG_RAW("    case cuda:\n")
17787
0
SLANG_RAW("        return WaveMaskReadLaneAt(WaveGetActiveMask(), value, lane);\n")
17788
0
SLANG_RAW("    }\n")
17789
0
SLANG_RAW("}\n")
17790
0
SLANG_RAW("\n")
17791
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17792
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
17793
0
SLANG_RAW("__spirv_version(1.3)\n")
17794
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17795
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_shuffle)]\n")
17796
0
SLANG_RAW("vector<T,N> WaveReadLaneAt(vector<T,N> value, int lane)\n")
17797
0
SLANG_RAW("{\n")
17798
0
SLANG_RAW("    __target_switch\n")
17799
0
SLANG_RAW("    {\n")
17800
0
SLANG_RAW("    case glsl:\n")
17801
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17802
0
SLANG_RAW("        __intrinsic_asm \"subgroupShuffle($0, $1)\";\n")
17803
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17804
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_shuffle($0, ushort($1))\";\n")
17805
0
SLANG_RAW("    case spirv:\n")
17806
0
SLANG_RAW("        let ulane = uint(lane);\n")
17807
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformShuffle; OpGroupNonUniformShuffle $$vector<T,N> result Subgroup $value $ulane};\n")
17808
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupShuffle\";\n")
17809
0
SLANG_RAW("    case cuda:\n")
17810
0
SLANG_RAW("        return WaveMaskReadLaneAt(WaveGetActiveMask(), value, lane);\n")
17811
0
SLANG_RAW("    }\n")
17812
0
SLANG_RAW("}\n")
17813
0
SLANG_RAW("\n")
17814
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17815
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_shuffle)]\n")
17816
0
SLANG_RAW("matrix<T, N, M> WaveReadLaneAt(matrix<T, N, M> value, int lane)\n")
17817
0
SLANG_RAW("{\n")
17818
0
SLANG_RAW("    __target_switch\n")
17819
0
SLANG_RAW("    {\n")
17820
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_waveShuffleMultiple(_getActiveMask(), $0, $1)\";\n")
17821
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17822
0
SLANG_RAW("    default:\n")
17823
0
SLANG_RAW("        matrix<T,N,M> result;\n")
17824
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
17825
0
SLANG_RAW("            result[i] = WaveReadLaneAt(value[i], lane);\n")
17826
0
SLANG_RAW("        return result;\n")
17827
0
SLANG_RAW("    }\n")
17828
0
SLANG_RAW("}\n")
17829
0
SLANG_RAW("\n")
17830
0
SLANG_RAW("// NOTE! WaveShuffle is a NON STANDARD HLSL intrinsic! It will map to WaveReadLaneAt on HLSL\n")
17831
0
SLANG_RAW("// which means it will only work on hardware which allows arbitrary laneIds which is not true\n")
17832
0
SLANG_RAW("// in general because it breaks the HLSL standard, which requires it's 'dynamically uniform' across the Wave.\n")
17833
0
SLANG_RAW("/// @category wave\n")
17834
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17835
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
17836
0
SLANG_RAW("__spirv_version(1.3)\n")
17837
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17838
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_shuffle)]\n")
17839
0
SLANG_RAW("T WaveShuffle(T value, int lane)\n")
17840
0
SLANG_RAW("{\n")
17841
0
SLANG_RAW("    __target_switch\n")
17842
0
SLANG_RAW("    {\n")
17843
0
SLANG_RAW("    case glsl:\n")
17844
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17845
0
SLANG_RAW("        __intrinsic_asm \"subgroupShuffle($0, $1)\";\n")
17846
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17847
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_shuffle($0, ushort($1))\";\n")
17848
0
SLANG_RAW("    case spirv:\n")
17849
0
SLANG_RAW("        let ulane = uint(lane);\n")
17850
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformShuffle; OpGroupNonUniformShuffle $$T result Subgroup $value $ulane};\n")
17851
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupShuffle\";\n")
17852
0
SLANG_RAW("    case cuda:\n")
17853
0
SLANG_RAW("        return WaveMaskShuffle(WaveGetActiveMask(), value, lane);\n")
17854
0
SLANG_RAW("    }\n")
17855
0
SLANG_RAW("}\n")
17856
0
SLANG_RAW("\n")
17857
0
SLANG_RAW("/// @category wave\n")
17858
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17859
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_shuffle)\n")
17860
0
SLANG_RAW("__spirv_version(1.3)\n")
17861
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17862
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_shuffle)]\n")
17863
0
SLANG_RAW("vector<T,N> WaveShuffle(vector<T,N> value, int lane)\n")
17864
0
SLANG_RAW("{\n")
17865
0
SLANG_RAW("    __target_switch\n")
17866
0
SLANG_RAW("    {\n")
17867
0
SLANG_RAW("    case glsl:\n")
17868
0
SLANG_RAW("        if (__isHalf<T>()) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
17869
0
SLANG_RAW("        __intrinsic_asm \"subgroupShuffle($0, $1)\";\n")
17870
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17871
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_shuffle($0, ushort($1))\";\n")
17872
0
SLANG_RAW("    case spirv:\n")
17873
0
SLANG_RAW("        let ulane = uint(lane);\n")
17874
0
SLANG_RAW("        return spirv_asm {OpCapability GroupNonUniformShuffle; OpGroupNonUniformShuffle $$vector<T,N> result Subgroup $value $ulane};\n")
17875
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"subgroupShuffle\";\n")
17876
0
SLANG_RAW("    case cuda:\n")
17877
0
SLANG_RAW("        return WaveMaskShuffle(WaveGetActiveMask(), value, lane);\n")
17878
0
SLANG_RAW("    }\n")
17879
0
SLANG_RAW("}\n")
17880
0
SLANG_RAW("\n")
17881
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17882
0
SLANG_RAW("[require(cuda_hlsl, subgroup_shuffle)]\n")
17883
0
SLANG_RAW("matrix<T, N, M> WaveShuffle(matrix<T, N, M> value, int lane)\n")
17884
0
SLANG_RAW("{\n")
17885
0
SLANG_RAW("    __target_switch\n")
17886
0
SLANG_RAW("    {\n")
17887
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveReadLaneAt\";\n")
17888
0
SLANG_RAW("    default:\n")
17889
0
SLANG_RAW("        return WaveMaskShuffle(WaveGetActiveMask(), value, lane);\n")
17890
0
SLANG_RAW("    }\n")
17891
0
SLANG_RAW("}\n")
17892
0
SLANG_RAW("\n")
17893
0
SLANG_RAW("/// @category wave\n")
17894
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17895
0
SLANG_RAW("__spirv_version(1.3)\n")
17896
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_ballot)]\n")
17897
0
SLANG_RAW("uint WavePrefixCountBits(bool value)\n")
17898
0
SLANG_RAW("{\n")
17899
0
SLANG_RAW("    __target_switch\n")
17900
0
SLANG_RAW("    {\n")
17901
0
SLANG_RAW("    case glsl:\n")
17902
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallotExclusiveBitCount(subgroupBallot($0))\";\n")
17903
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WavePrefixCountBits($0)\";\n")
17904
0
SLANG_RAW("    case spirv:\n")
17905
0
SLANG_RAW("        return spirv_asm\n")
17906
0
SLANG_RAW("        {\n")
17907
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
17908
0
SLANG_RAW("            %mask:$$uint4 = OpGroupNonUniformBallot Subgroup $value;\n")
17909
0
SLANG_RAW("            OpGroupNonUniformBallotBitCount $$uint result Subgroup 2 %mask\n")
17910
0
SLANG_RAW("        };\n")
17911
0
SLANG_RAW("    default:\n")
17912
0
SLANG_RAW("        return WaveMaskPrefixCountBits(WaveGetActiveMask(), value);\n")
17913
0
SLANG_RAW("    }\n")
17914
0
SLANG_RAW("}\n")
17915
0
SLANG_RAW("\n")
17916
0
SLANG_RAW("/// @category wave\n")
17917
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_ballot)\n")
17918
0
SLANG_RAW("__spirv_version(1.3)\n")
17919
0
SLANG_RAW("__wgsl_extension(subgroups)\n")
17920
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv_wgsl, subgroup_ballot)]\n")
17921
0
SLANG_RAW("uint4 WaveGetConvergedMulti()\n")
17922
0
SLANG_RAW("{\n")
17923
0
SLANG_RAW("    __target_switch\n")
17924
0
SLANG_RAW("    {\n")
17925
0
SLANG_RAW("    case glsl:\n")
17926
0
SLANG_RAW("    case wgsl:\n")
17927
0
SLANG_RAW("        __intrinsic_asm \"subgroupBallot(true)\";\n")
17928
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveActiveBallot(true)\";\n")
17929
0
SLANG_RAW("    case cuda: __intrinsic_asm \"make_uint4(__activemask(), 0, 0, 0)\";\n")
17930
0
SLANG_RAW("    case metal: __intrinsic_asm \"((uint4)((simd_vote::vote_t)simd_ballot(true)))\";\n")
17931
0
SLANG_RAW("    case spirv:\n")
17932
0
SLANG_RAW("        let _true = true;\n")
17933
0
SLANG_RAW("        return spirv_asm\n")
17934
0
SLANG_RAW("        {\n")
17935
0
SLANG_RAW("            OpCapability GroupNonUniformBallot;\n")
17936
0
SLANG_RAW("            OpGroupNonUniformBallot $$uint4 result Subgroup $_true\n")
17937
0
SLANG_RAW("        };\n")
17938
0
SLANG_RAW("    }\n")
17939
0
SLANG_RAW("}\n")
17940
0
SLANG_RAW("\n")
17941
0
SLANG_RAW("/// @category wave\n")
17942
0
SLANG_RAW("[ForceInline]\n")
17943
0
SLANG_RAW("uint4 WaveGetActiveMulti()\n")
17944
0
SLANG_RAW("{\n")
17945
0
SLANG_RAW("    return WaveGetConvergedMulti();\n")
17946
0
SLANG_RAW("}\n")
17947
0
SLANG_RAW("\n")
17948
0
SLANG_RAW("// Shader model 6.5 stuff\n")
17949
0
SLANG_RAW("// https://github.com/microsoft/DirectX-Specs/blob/master/d3d/HLSL_ShaderModel6_5.md\n")
17950
0
SLANG_RAW("\n")
17951
0
SLANG_RAW("/// @category wave\n")
17952
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
17953
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
17954
0
SLANG_RAW("uint4 WaveMatch(T value)\n")
17955
0
SLANG_RAW("{\n")
17956
0
SLANG_RAW("    __target_switch\n")
17957
0
SLANG_RAW("    {\n")
17958
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch\";\n")
17959
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupPartitionNV($0)\";\n")
17960
0
SLANG_RAW("    case spirv:\n")
17961
0
SLANG_RAW("        return spirv_asm\n")
17962
0
SLANG_RAW("        {\n")
17963
0
SLANG_RAW("            OpCapability GroupNonUniformPartitionedNV;\n")
17964
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_subgroup_partitioned\";\n")
17965
0
SLANG_RAW("            OpGroupNonUniformPartitionNV $$uint4 result $value\n")
17966
0
SLANG_RAW("        };\n")
17967
0
SLANG_RAW("    default:\n")
17968
0
SLANG_RAW("        return WaveMaskMatch(WaveGetActiveMask(), value);\n")
17969
0
SLANG_RAW("    }\n")
17970
0
SLANG_RAW("}\n")
17971
0
SLANG_RAW("\n")
17972
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
17973
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
17974
0
SLANG_RAW("uint4 WaveMatch(vector<T,N> value)\n")
17975
0
SLANG_RAW("{\n")
17976
0
SLANG_RAW("    __target_switch\n")
17977
0
SLANG_RAW("    {\n")
17978
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch\";\n")
17979
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupPartitionNV($0)\";\n")
17980
0
SLANG_RAW("    case spirv:\n")
17981
0
SLANG_RAW("        return spirv_asm\n")
17982
0
SLANG_RAW("        {\n")
17983
0
SLANG_RAW("            OpCapability GroupNonUniformPartitionedNV;\n")
17984
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_subgroup_partitioned\";\n")
17985
0
SLANG_RAW("            OpGroupNonUniformPartitionNV $$uint4 result $value\n")
17986
0
SLANG_RAW("        };\n")
17987
0
SLANG_RAW("    default:\n")
17988
0
SLANG_RAW("        return WaveMaskMatch(WaveGetActiveMask(), value);\n")
17989
0
SLANG_RAW("    }\n")
17990
0
SLANG_RAW("}\n")
17991
0
SLANG_RAW("\n")
17992
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int>\n")
17993
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
17994
0
SLANG_RAW("uint4 WaveMatch(matrix<T,N,M> value)\n")
17995
0
SLANG_RAW("{\n")
17996
0
SLANG_RAW("    __target_switch\n")
17997
0
SLANG_RAW("    {\n")
17998
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMatch\";\n")
17999
0
SLANG_RAW("    case glsl:\n")
18000
0
SLANG_RAW("    case cuda:\n")
18001
0
SLANG_RAW("    case spirv:\n")
18002
0
SLANG_RAW("        uint4 result = uint4(0xFFFFFFFF);\n")
18003
0
SLANG_RAW("        [ForceUnroll]\n")
18004
0
SLANG_RAW("        for (int i = 0; i < N; i++)\n")
18005
0
SLANG_RAW("            result &= WaveMatch(value[i]);\n")
18006
0
SLANG_RAW("        return result;\n")
18007
0
SLANG_RAW("    default:\n")
18008
0
SLANG_RAW("        return WaveMaskMatch(WaveGetActiveMask(), value);\n")
18009
0
SLANG_RAW("    }\n")
18010
0
SLANG_RAW("}\n")
18011
0
SLANG_RAW("\n")
18012
0
SLANG_RAW("/// @category wave\n")
18013
0
SLANG_RAW("[require(cuda_hlsl, subgroup_partitioned)]\n")
18014
0
SLANG_RAW("uint WaveMultiPrefixCountBits(bool value, uint4 mask)\n")
18015
0
SLANG_RAW("{\n")
18016
0
SLANG_RAW("    __target_switch\n")
18017
0
SLANG_RAW("    {\n")
18018
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_popc(__ballot_sync(($1).x, $0) & _getLaneLtMask())\";\n")
18019
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"WaveMultiPrefixCountBits\";\n")
18020
0
SLANG_RAW("    }\n")
18021
0
SLANG_RAW("}\n")
18022
0
SLANG_RAW("\n")
18023
0
SLANG_RAW("__glsl_extension(GL_EXT_demote_to_helper_invocation)\n")
18024
0
SLANG_RAW("[ForceInline]\n")
18025
0
SLANG_RAW("[require(glsl_hlsl_metal_spirv, helper_lane)]\n")
18026
0
SLANG_RAW("bool IsHelperLane()\n")
18027
0
SLANG_RAW("{\n")
18028
0
SLANG_RAW("    __target_switch {\n")
18029
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"IsHelperLane()\";\n")
18030
0
SLANG_RAW("    case glsl: __intrinsic_asm \"gl_HelperInvocation\";\n")
18031
0
SLANG_RAW("    case metal: __intrinsic_asm \"simd_is_helper_thread()\";\n")
18032
0
SLANG_RAW("    case spirv:\n")
18033
0
SLANG_RAW("        return spirv_asm {\n")
18034
0
SLANG_RAW("            OpExtension \"SPV_EXT_demote_to_helper_invocation\";\n")
18035
0
SLANG_RAW("            OpCapability DemoteToHelperInvocationEXT;\n")
18036
0
SLANG_RAW("            result:$$bool = OpIsHelperInvocationEXT\n")
18037
0
SLANG_RAW("        };\n")
18038
0
SLANG_RAW("    }\n")
18039
0
SLANG_RAW("}\n")
18040
0
SLANG_RAW("\n")
18041
0
SLANG_RAW("//@hidden:\n")
18042
0
SLANG_RAW("\n")
18043
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18044
0
SLANG_RAW("[ForceInline]\n")
18045
0
SLANG_RAW("[require(glsl)]\n")
18046
0
SLANG_RAW("void __requireGLSLShaderSubgroupTypeExtension()\n")
18047
0
SLANG_RAW("{\n")
18048
0
SLANG_RAW("    // the following is a seperate function call, since else the `__requireTargetExtension` and associated __intrinsic_asm is ignored if the calling function also calls an __intrinsic_asm\n")
18049
0
SLANG_RAW("    if (__type_equals<T, half>()\n")
18050
0
SLANG_RAW("        || __type_equals<T, float16_t>()\n")
18051
0
SLANG_RAW("        ) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_float16\");\n")
18052
0
SLANG_RAW("    else if (__type_equals<T, uint8_t>()\n")
18053
0
SLANG_RAW("        || __type_equals<T, int8_t>()\n")
18054
0
SLANG_RAW("        ) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_int8\");\n")
18055
0
SLANG_RAW("    else if (__type_equals<T, uint16_t>()\n")
18056
0
SLANG_RAW("        || __type_equals<T, int16_t>()\n")
18057
0
SLANG_RAW("        ) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_int16\");\n")
18058
0
SLANG_RAW("    else if (__type_equals<T, uint64_t>()\n")
18059
0
SLANG_RAW("        || __type_equals<T, int64_t>()\n")
18060
0
SLANG_RAW("        ) __requireTargetExtension(\"GL_EXT_shader_subgroup_extended_types_int64\");\n")
18061
0
SLANG_RAW("\n")
18062
0
SLANG_RAW("    __intrinsic_asm \"\";\n")
18063
0
SLANG_RAW("}\n")
18064
0
SLANG_RAW("\n")
18065
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18066
0
SLANG_RAW("[ForceInline]\n")
18067
0
SLANG_RAW("[require(metal)]\n")
18068
0
SLANG_RAW("void __checkMetalShaderSubgroupType()\n")
18069
0
SLANG_RAW("{\n")
18070
0
SLANG_RAW("    // These builtin types are not supported for Metal's `simd` operations.\n")
18071
0
SLANG_RAW("    if (__type_equals<T, uint8_t>()\n")
18072
0
SLANG_RAW("        || __type_equals<T, int8_t>()\n")
18073
0
SLANG_RAW("        || __type_equals<T, uint64_t>()\n")
18074
0
SLANG_RAW("        || __type_equals<T, int64_t>()\n")
18075
0
SLANG_RAW("        || __isBool<T>()\n")
18076
0
SLANG_RAW("        )\n")
18077
0
SLANG_RAW("    {\n")
18078
0
SLANG_RAW("        static_assert(false, \"Unsupported type for subgroup operations in Metal. Valid types include scalars and vectors of uint/uint32_t, int/int32_t, uint16_t, int16_t, float, and half.\");\n")
18079
0
SLANG_RAW("    }\n")
18080
0
SLANG_RAW("}\n")
18081
0
SLANG_RAW("\n")
18082
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18083
0
SLANG_RAW("[ForceInline]\n")
18084
0
SLANG_RAW("void shader_subgroup_preamble()\n")
18085
0
SLANG_RAW("{\n")
18086
0
SLANG_RAW("    // checks needed for shader_subgroup functions; __requireTargetExtension does not work\n")
18087
0
SLANG_RAW("    // (does not add the ext specified correctly to the compile output; using extended type\n")
18088
0
SLANG_RAW("    // will result in error for using the type)\n")
18089
0
SLANG_RAW("    __target_switch\n")
18090
0
SLANG_RAW("    {\n")
18091
0
SLANG_RAW("    case glsl:\n")
18092
0
SLANG_RAW("        __requireGLSLShaderSubgroupTypeExtension<T>();\n")
18093
0
SLANG_RAW("    case metal:\n")
18094
0
SLANG_RAW("        __checkMetalShaderSubgroupType<T>();\n")
18095
0
SLANG_RAW("    default:\n")
18096
0
SLANG_RAW("        return;\n")
18097
0
SLANG_RAW("    }\n")
18098
0
SLANG_RAW("}\n")
18099
0
SLANG_RAW("\n")
18100
0
SLANG_RAW("//@public:\n")
18101
0
SLANG_RAW("\n")
18102
0
SLANG_RAW("//\n")
18103
0
SLANG_RAW("// Wave Rotate intrinsics.\n")
18104
0
SLANG_RAW("// These are Slang specific intrinsics to rotate values within a subgroup.\n")
18105
0
SLANG_RAW("//\n")
18106
0
SLANG_RAW("\n")
18107
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18108
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_rotate)\n")
18109
0
SLANG_RAW("[require(cuda_glsl_metal_spirv, subgroup_rotate)]\n")
18110
0
SLANG_RAW("T WaveRotate(T value, uint delta)\n")
18111
0
SLANG_RAW("{\n")
18112
0
SLANG_RAW("    shader_subgroup_preamble<T>();\n")
18113
0
SLANG_RAW("    __target_switch\n")
18114
0
SLANG_RAW("    {\n")
18115
0
SLANG_RAW("    case glsl:\n")
18116
0
SLANG_RAW("        __intrinsic_asm \"subgroupRotate\";\n")
18117
0
SLANG_RAW("    case cuda:\n")
18118
0
SLANG_RAW("        __intrinsic_asm \"__shfl_sync(0xFFFFFFFF, $0, (_getLaneId() + $1) % 32)\";\n")
18119
0
SLANG_RAW("    case metal:\n")
18120
0
SLANG_RAW("        __intrinsic_asm \"simd_shuffle_rotate_down\";\n")
18121
0
SLANG_RAW("    case spirv:\n")
18122
0
SLANG_RAW("        return spirv_asm\n")
18123
0
SLANG_RAW("        {\n")
18124
0
SLANG_RAW("            OpExtension \"SPV_KHR_subgroup_rotate\";\n")
18125
0
SLANG_RAW("            OpCapability GroupNonUniformRotateKHR;\n")
18126
0
SLANG_RAW("            result:$$T = OpGroupNonUniformRotateKHR Subgroup $value $delta;\n")
18127
0
SLANG_RAW("        };\n")
18128
0
SLANG_RAW("    }\n")
18129
0
SLANG_RAW("}\n")
18130
0
SLANG_RAW("\n")
18131
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
18132
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_rotate)\n")
18133
0
SLANG_RAW("[require(cuda_glsl_metal_spirv, subgroup_rotate)]\n")
18134
0
SLANG_RAW("vector<T, N> WaveRotate(vector<T, N> value, uint delta)\n")
18135
0
SLANG_RAW("{\n")
18136
0
SLANG_RAW("    shader_subgroup_preamble<T>();\n")
18137
0
SLANG_RAW("    __target_switch\n")
18138
0
SLANG_RAW("    {\n")
18139
0
SLANG_RAW("    case glsl:\n")
18140
0
SLANG_RAW("        __intrinsic_asm \"subgroupRotate\";\n")
18141
0
SLANG_RAW("    case cuda:\n")
18142
0
SLANG_RAW("        __intrinsic_asm \"_slang_waveRotate($0, $1)\";\n")
18143
0
SLANG_RAW("    case metal:\n")
18144
0
SLANG_RAW("        __intrinsic_asm \"simd_shuffle_rotate_down\";\n")
18145
0
SLANG_RAW("    case spirv:\n")
18146
0
SLANG_RAW("        return spirv_asm\n")
18147
0
SLANG_RAW("        {\n")
18148
0
SLANG_RAW("            OpExtension \"SPV_KHR_subgroup_rotate\";\n")
18149
0
SLANG_RAW("            OpCapability GroupNonUniformRotateKHR;\n")
18150
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformRotateKHR Subgroup $value $delta;\n")
18151
0
SLANG_RAW("        };\n")
18152
0
SLANG_RAW("    }\n")
18153
0
SLANG_RAW("}\n")
18154
0
SLANG_RAW("\n")
18155
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18156
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_rotate)\n")
18157
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_rotate)]\n")
18158
0
SLANG_RAW("T WaveClusteredRotate(T value, uint delta, constexpr uint clusterSize)\n")
18159
0
SLANG_RAW("{\n")
18160
0
SLANG_RAW("    shader_subgroup_preamble<T>();\n")
18161
0
SLANG_RAW("    __target_switch\n")
18162
0
SLANG_RAW("    {\n")
18163
0
SLANG_RAW("    case glsl:\n")
18164
0
SLANG_RAW("        __intrinsic_asm \"subgroupClusteredRotate\";\n")
18165
0
SLANG_RAW("    case cuda:\n")
18166
0
SLANG_RAW("        __intrinsic_asm \"_slang_waveClusteredRotate($0, $1, $2)\";\n")
18167
0
SLANG_RAW("    case spirv:\n")
18168
0
SLANG_RAW("        return spirv_asm\n")
18169
0
SLANG_RAW("        {\n")
18170
0
SLANG_RAW("            OpExtension \"SPV_KHR_subgroup_rotate\";\n")
18171
0
SLANG_RAW("            OpCapability GroupNonUniformRotateKHR;\n")
18172
0
SLANG_RAW("            result:$$T = OpGroupNonUniformRotateKHR Subgroup $value $delta $clusterSize;\n")
18173
0
SLANG_RAW("        };\n")
18174
0
SLANG_RAW("    }\n")
18175
0
SLANG_RAW("}\n")
18176
0
SLANG_RAW("\n")
18177
0
SLANG_RAW("__generic<T : __BuiltinType, let N : int>\n")
18178
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_rotate)\n")
18179
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_rotate)]\n")
18180
0
SLANG_RAW("vector<T, N> WaveClusteredRotate(vector<T, N> value, uint delta, constexpr uint clusterSize)\n")
18181
0
SLANG_RAW("{\n")
18182
0
SLANG_RAW("    shader_subgroup_preamble<T>();\n")
18183
0
SLANG_RAW("    __target_switch\n")
18184
0
SLANG_RAW("    {\n")
18185
0
SLANG_RAW("    case glsl:\n")
18186
0
SLANG_RAW("        __intrinsic_asm \"subgroupClusteredRotate\";\n")
18187
0
SLANG_RAW("    case cuda:\n")
18188
0
SLANG_RAW("        __intrinsic_asm \"_slang_waveClusteredRotate($0, $1, $2)\";\n")
18189
0
SLANG_RAW("    case spirv:\n")
18190
0
SLANG_RAW("        return spirv_asm\n")
18191
0
SLANG_RAW("        {\n")
18192
0
SLANG_RAW("            OpExtension \"SPV_KHR_subgroup_rotate\";\n")
18193
0
SLANG_RAW("            OpCapability GroupNonUniformRotateKHR;\n")
18194
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformRotateKHR Subgroup $value $delta $clusterSize;\n")
18195
0
SLANG_RAW("        };\n")
18196
0
SLANG_RAW("    }\n")
18197
0
SLANG_RAW("}\n")
18198
0
SLANG_RAW("\n")
18199
0
SLANG_RAW("\n")
18200
0
SLANG_RAW("//\n")
18201
0
SLANG_RAW("// WaveMulti intrinsics are subgroup operations that operate on a 128-bit `uint4` mask.\n")
18202
0
SLANG_RAW("// They are equivalent to SPIRV/GLSL's subgroup partitioned operation and HLSL's `WaveMultiPrefix*` operations.\n")
18203
0
SLANG_RAW("//\n")
18204
0
SLANG_RAW("// SPIRV/GLSL natively supports masked subgroup operations for both reductions and exclusive/inclusive scans.\n")
18205
0
SLANG_RAW("// HLSL only natively supports exclusive scans(prefix operations) on arithmetic operations. Inclusve scans\n")
18206
0
SLANG_RAW("// are emulated by performing an additional operation to the inclusive scan result. Reductions are not supported.\n")
18207
0
SLANG_RAW("//\n")
18208
0
SLANG_RAW("\n")
18209
0
SLANG_RAW("__generic<T : __BuiltinType>\n")
18210
0
SLANG_RAW("[ForceInline]\n")
18211
0
SLANG_RAW("void __shaderSubgroupPartitionedPreamble()\n")
18212
0
SLANG_RAW("{\n")
18213
0
SLANG_RAW("    shader_subgroup_preamble<T>();\n")
18214
0
SLANG_RAW("    __target_switch\n")
18215
0
SLANG_RAW("    {\n")
18216
0
SLANG_RAW("    case glsl:\n")
18217
0
SLANG_RAW("        __requireTargetExtension(\"GL_NV_shader_subgroup_partitioned\");\n")
18218
0
SLANG_RAW("    case spirv:\n")
18219
0
SLANG_RAW("        spirv_asm\n")
18220
0
SLANG_RAW("        {\n")
18221
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_subgroup_partitioned\";\n")
18222
0
SLANG_RAW("            OpCapability GroupNonUniformPartitionedNV;\n")
18223
0
SLANG_RAW("        };\n")
18224
0
SLANG_RAW("    default:\n")
18225
0
SLANG_RAW("        return;\n")
18226
0
SLANG_RAW("    }\n")
18227
0
SLANG_RAW("}\n")
18228
0
SLANG_RAW("\n")
18229
0
SLANG_RAW("//\n")
18230
0
SLANG_RAW("// WaveMultiSum/WaveMultiProduct.\n")
18231
0
SLANG_RAW("//\n")
18232
18233
0
struct WaveMultiSumProductEntry { const char* name; const char* spirvName; };
18234
0
const WaveMultiSumProductEntry kWaveMultiSumProductNames[] = { {"Sum", "Add"}, {"Product", "Mul"} };
18235
0
for (auto opName : kWaveMultiSumProductNames) {
18236
0
SLANG_RAW("#line 16566 \"hlsl.meta.slang\"")
18237
0
SLANG_RAW("\n")
18238
0
SLANG_RAW("\n")
18239
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
18240
0
SLANG_RAW("__spirv_version(1.3)\n")
18241
0
SLANG_RAW("[ForceInline]\n")
18242
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18243
0
SLANG_RAW("T WaveMulti")
18244
0
SLANG_SPLICE(opName.name
18245
0
)
18246
0
SLANG_RAW("(T value, uint4 mask)\n")
18247
0
SLANG_RAW("{\n")
18248
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18249
0
SLANG_RAW("    __target_switch\n")
18250
0
SLANG_RAW("    {\n")
18251
0
SLANG_RAW("    case cuda:\n")
18252
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18253
0
SLANG_SPLICE(opName.name
18254
0
)
18255
0
SLANG_RAW("($1.x, $0)\";\n")
18256
0
SLANG_RAW("    case glsl:\n")
18257
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18258
0
SLANG_SPLICE(opName.spirvName
18259
0
)
18260
0
SLANG_RAW("NV\";\n")
18261
0
SLANG_RAW("    case spirv:\n")
18262
0
SLANG_RAW("        {\n")
18263
0
SLANG_RAW("            if (__isFloat<T>())\n")
18264
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformF")
18265
0
SLANG_SPLICE(opName.spirvName
18266
0
)
18267
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18268
0
SLANG_RAW("            else\n")
18269
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformI")
18270
0
SLANG_SPLICE(opName.spirvName
18271
0
)
18272
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18273
0
SLANG_RAW("        }\n")
18274
0
SLANG_RAW("    }\n")
18275
0
SLANG_RAW("}\n")
18276
0
SLANG_RAW("\n")
18277
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
18278
0
SLANG_RAW("__spirv_version(1.3)\n")
18279
0
SLANG_RAW("[ForceInline]\n")
18280
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18281
0
SLANG_RAW("vector<T, N> WaveMulti")
18282
0
SLANG_SPLICE(opName.name
18283
0
)
18284
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
18285
0
SLANG_RAW("{\n")
18286
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18287
0
SLANG_RAW("    __target_switch\n")
18288
0
SLANG_RAW("    {\n")
18289
0
SLANG_RAW("    case cuda:\n")
18290
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18291
0
SLANG_SPLICE(opName.name
18292
0
)
18293
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18294
0
SLANG_RAW("    case glsl:\n")
18295
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18296
0
SLANG_SPLICE(opName.spirvName
18297
0
)
18298
0
SLANG_RAW("NV\";\n")
18299
0
SLANG_RAW("    case spirv:\n")
18300
0
SLANG_RAW("        {\n")
18301
0
SLANG_RAW("            if (__isFloat<T>())\n")
18302
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformF")
18303
0
SLANG_SPLICE(opName.spirvName
18304
0
)
18305
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18306
0
SLANG_RAW("            else\n")
18307
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformI")
18308
0
SLANG_SPLICE(opName.spirvName
18309
0
)
18310
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18311
0
SLANG_RAW("        }\n")
18312
0
SLANG_RAW("    }\n")
18313
0
SLANG_RAW("}\n")
18314
0
SLANG_RAW("\n")
18315
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
18316
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18317
0
SLANG_RAW("matrix<T,N,M> WaveMulti")
18318
0
SLANG_SPLICE(opName.name
18319
0
)
18320
0
SLANG_RAW("(matrix<T,N,M> value, uint4 mask)\n")
18321
0
SLANG_RAW("{\n")
18322
0
SLANG_RAW("    __target_switch\n")
18323
0
SLANG_RAW("    {\n")
18324
0
SLANG_RAW("    case cuda:\n")
18325
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18326
0
SLANG_SPLICE(opName.name
18327
0
)
18328
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18329
0
SLANG_RAW("    default:\n")
18330
0
SLANG_RAW("        matrix<T, N, M> result;\n")
18331
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
18332
0
SLANG_RAW("            result[i] = WaveMulti")
18333
0
SLANG_SPLICE(opName.name
18334
0
)
18335
0
SLANG_RAW("(value[i], mask);\n")
18336
0
SLANG_RAW("        return result;\n")
18337
0
SLANG_RAW("    }\n")
18338
0
SLANG_RAW("}\n")
18339
0
SLANG_RAW("\n")
18340
18341
0
} // WaveMultiSum/WaveMultiProduct.
18342
0
SLANG_RAW("#line 16632 \"hlsl.meta.slang\"")
18343
0
SLANG_RAW("\n")
18344
0
SLANG_RAW("\n")
18345
0
SLANG_RAW("\n")
18346
0
SLANG_RAW("//\n")
18347
0
SLANG_RAW("// WaveMultiPrefixInclusiveSum/WaveMultiPrefixInclusiveProduct.\n")
18348
0
SLANG_RAW("// WaveMultiPrefixExclusiveSum/WaveMultiPrefixExclusiveProduct.\n")
18349
0
SLANG_RAW("// WaveMultiPrefixSum/WaveMultiPrefixProduct.\n")
18350
0
SLANG_RAW("//\n")
18351
18352
0
struct WaveMultiPrefixSumProductEntry
18353
0
{
18354
0
    const char* name;
18355
0
    const char* spirvName;
18356
0
    const char* spirvGroupOperation;
18357
0
    const char* glslName;
18358
0
    const char* hlslName;
18359
0
    const char* cudaName;
18360
0
    const char* cudaExtraOperation;
18361
18362
    // Inclusive operations are not implemented by the CUDA prelude functions.
18363
    // They are implemented here by calling the exclusive implementation and performing an additional operations
18364
    // with the current invocation's value. This works for all cases except for element-wise matrix multiplication.
18365
0
    bool cudaMatrixVariantSupport;
18366
0
};
18367
18368
0
const WaveMultiPrefixSumProductEntry kWaveMultiPrefixSumProductNames[] =
18369
0
{
18370
    // name               spirvName  spirvGroupOperation         glslName        hlslName                         cudaName     cudaExtraOperation   cudaMatrixVariantSupport
18371
0
    { "InclusiveSum",     "Add",     "PartitionedInclusiveScanNV", "InclusiveAdd", "Sum($0, $1) + $0",              "Sum",       "+ $0",            false },
18372
0
    { "InclusiveProduct", "Mul",     "PartitionedInclusiveScanNV", "InclusiveMul", "Product($0, $1) * $0",          "Product",   "* $0",            false },
18373
0
    { "ExclusiveSum",     "Add",     "PartitionedExclusiveScanNV", "ExclusiveAdd", "Sum($0, $1)",                   "Sum",       "",                true  },
18374
0
    { "ExclusiveProduct", "Mul",     "PartitionedExclusiveScanNV", "ExclusiveMul", "Product($0, $1)",               "Product",   "",                true  },
18375
18376
    // These are HLSL SM 6.5 intrinsics and are equal to the exclusive variants.
18377
0
    { "Sum",              "Add",     "PartitionedExclusiveScanNV", "ExclusiveAdd", "Sum($0, $1)",                   "Sum",       "",                true  },
18378
0
    { "Product",          "Mul",     "PartitionedExclusiveScanNV", "ExclusiveMul", "Product($0, $1)",               "Product",   "",                true  },
18379
0
};
18380
18381
0
for (auto opName : kWaveMultiPrefixSumProductNames) {
18382
0
SLANG_RAW("#line 16671 \"hlsl.meta.slang\"")
18383
0
SLANG_RAW("\n")
18384
0
SLANG_RAW("\n")
18385
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
18386
0
SLANG_RAW("__spirv_version(1.3)\n")
18387
0
SLANG_RAW("[ForceInline]\n")
18388
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
18389
0
SLANG_RAW("T WaveMultiPrefix")
18390
0
SLANG_SPLICE(opName.name
18391
0
)
18392
0
SLANG_RAW("(T value, uint4 mask)\n")
18393
0
SLANG_RAW("{\n")
18394
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18395
0
SLANG_RAW("    __target_switch\n")
18396
0
SLANG_RAW("    {\n")
18397
0
SLANG_RAW("    case cuda:\n")
18398
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18399
0
SLANG_SPLICE(opName.cudaName
18400
0
)
18401
0
SLANG_RAW("($1.x, $0) ")
18402
0
SLANG_SPLICE(opName.cudaExtraOperation
18403
0
)
18404
0
SLANG_RAW("\";\n")
18405
0
SLANG_RAW("    case glsl:\n")
18406
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18407
0
SLANG_SPLICE(opName.glslName
18408
0
)
18409
0
SLANG_RAW("NV\";\n")
18410
0
SLANG_RAW("    case hlsl:\n")
18411
0
SLANG_RAW("        __intrinsic_asm \"WaveMultiPrefix")
18412
0
SLANG_SPLICE(opName.hlslName
18413
0
)
18414
0
SLANG_RAW("\";\n")
18415
0
SLANG_RAW("    case spirv:\n")
18416
0
SLANG_RAW("        {\n")
18417
0
SLANG_RAW("            if (__isFloat<T>())\n")
18418
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformF")
18419
0
SLANG_SPLICE(opName.spirvName
18420
0
)
18421
0
SLANG_RAW(" Subgroup ")
18422
0
SLANG_SPLICE(opName.spirvGroupOperation
18423
0
)
18424
0
SLANG_RAW(" $value $mask };\n")
18425
0
SLANG_RAW("            else\n")
18426
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformI")
18427
0
SLANG_SPLICE(opName.spirvName
18428
0
)
18429
0
SLANG_RAW(" Subgroup ")
18430
0
SLANG_SPLICE(opName.spirvGroupOperation
18431
0
)
18432
0
SLANG_RAW(" $value $mask };\n")
18433
0
SLANG_RAW("        }\n")
18434
0
SLANG_RAW("    }\n")
18435
0
SLANG_RAW("}\n")
18436
0
SLANG_RAW("\n")
18437
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
18438
0
SLANG_RAW("__spirv_version(1.3)\n")
18439
0
SLANG_RAW("[ForceInline]\n")
18440
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
18441
0
SLANG_RAW("vector<T, N> WaveMultiPrefix")
18442
0
SLANG_SPLICE(opName.name
18443
0
)
18444
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
18445
0
SLANG_RAW("{\n")
18446
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18447
0
SLANG_RAW("    __target_switch\n")
18448
0
SLANG_RAW("    {\n")
18449
0
SLANG_RAW("    case cuda:\n")
18450
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18451
0
SLANG_SPLICE(opName.cudaName
18452
0
)
18453
0
SLANG_RAW("Multiple($1.x, $0) ")
18454
0
SLANG_SPLICE(opName.cudaExtraOperation
18455
0
)
18456
0
SLANG_RAW("\";\n")
18457
0
SLANG_RAW("    case glsl:\n")
18458
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18459
0
SLANG_SPLICE(opName.glslName
18460
0
)
18461
0
SLANG_RAW("NV\";\n")
18462
0
SLANG_RAW("    case hlsl:\n")
18463
0
SLANG_RAW("        __intrinsic_asm \"WaveMultiPrefix")
18464
0
SLANG_SPLICE(opName.hlslName
18465
0
)
18466
0
SLANG_RAW("\";\n")
18467
0
SLANG_RAW("    case spirv:\n")
18468
0
SLANG_RAW("        {\n")
18469
0
SLANG_RAW("            if (__isFloat<T>())\n")
18470
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformF")
18471
0
SLANG_SPLICE(opName.spirvName
18472
0
)
18473
0
SLANG_RAW(" Subgroup ")
18474
0
SLANG_SPLICE(opName.spirvGroupOperation
18475
0
)
18476
0
SLANG_RAW(" $value $mask };\n")
18477
0
SLANG_RAW("            else\n")
18478
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformI")
18479
0
SLANG_SPLICE(opName.spirvName
18480
0
)
18481
0
SLANG_RAW(" Subgroup ")
18482
0
SLANG_SPLICE(opName.spirvGroupOperation
18483
0
)
18484
0
SLANG_RAW(" $value $mask };\n")
18485
0
SLANG_RAW("        }\n")
18486
0
SLANG_RAW("    }\n")
18487
0
SLANG_RAW("}\n")
18488
0
SLANG_RAW("\n")
18489
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
18490
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
18491
0
SLANG_RAW("matrix<T,N,M> WaveMultiPrefix")
18492
0
SLANG_SPLICE(opName.name
18493
0
)
18494
0
SLANG_RAW("(matrix<T,N,M> value, uint4 mask)\n")
18495
0
SLANG_RAW("{\n")
18496
0
SLANG_RAW("    __target_switch\n")
18497
0
SLANG_RAW("    {\n")
18498
0
 if(opName.cudaMatrixVariantSupport) { 
18499
0
SLANG_RAW("#line 16729 \"hlsl.meta.slang\"")
18500
0
SLANG_RAW("\n")
18501
0
SLANG_RAW("    case cuda:\n")
18502
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18503
0
SLANG_SPLICE(opName.cudaName
18504
0
)
18505
0
SLANG_RAW("Multiple($1.x, $0) ")
18506
0
SLANG_SPLICE(opName.cudaExtraOperation
18507
0
)
18508
0
SLANG_RAW("\";\n")
18509
0
 } 
18510
0
SLANG_RAW("#line 16732 \"hlsl.meta.slang\"")
18511
0
SLANG_RAW("\n")
18512
0
SLANG_RAW("    default:\n")
18513
0
SLANG_RAW("        matrix<T, N, M> result;\n")
18514
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
18515
0
SLANG_RAW("            result[i] = WaveMultiPrefix")
18516
0
SLANG_SPLICE(opName.name
18517
0
)
18518
0
SLANG_RAW("(value[i], mask);\n")
18519
0
SLANG_RAW("        return result;\n")
18520
0
SLANG_RAW("    }\n")
18521
0
SLANG_RAW("}\n")
18522
0
SLANG_RAW("\n")
18523
18524
0
}
18525
// WaveMultiPrefixInclusiveSum/WaveMultiPrefixInclusiveProduct.
18526
// WaveMultiPrefixExclusiveSum/WaveMultiPrefixExclusiveProduct.
18527
// WaveMultiPrefixSum/WaveMultiPrefixProduct.
18528
0
SLANG_RAW("#line 16746 \"hlsl.meta.slang\"")
18529
0
SLANG_RAW("\n")
18530
0
SLANG_RAW("\n")
18531
0
SLANG_RAW("\n")
18532
0
SLANG_RAW("//\n")
18533
0
SLANG_RAW("// WaveMultiMin/WaveMultiMax.\n")
18534
0
SLANG_RAW("//\n")
18535
18536
0
struct WaveMultiMinMaxEntry { const char* name; };
18537
0
const WaveMultiMinMaxEntry kWaveMultiMinMaxNames[] = { {"Min"}, {"Max"} };
18538
0
for (auto opName : kWaveMultiMinMaxNames) {
18539
0
SLANG_RAW("#line 16756 \"hlsl.meta.slang\"")
18540
0
SLANG_RAW("\n")
18541
0
SLANG_RAW("\n")
18542
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
18543
0
SLANG_RAW("__spirv_version(1.3)\n")
18544
0
SLANG_RAW("[ForceInline]\n")
18545
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18546
0
SLANG_RAW("T WaveMulti")
18547
0
SLANG_SPLICE(opName.name
18548
0
)
18549
0
SLANG_RAW("(T value, uint4 mask)\n")
18550
0
SLANG_RAW("{\n")
18551
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18552
0
SLANG_RAW("    __target_switch\n")
18553
0
SLANG_RAW("    {\n")
18554
0
SLANG_RAW("    case cuda:\n")
18555
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18556
0
SLANG_SPLICE(opName.name
18557
0
)
18558
0
SLANG_RAW("($1.x, $0)\";\n")
18559
0
SLANG_RAW("    case glsl:\n")
18560
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18561
0
SLANG_SPLICE(opName.name
18562
0
)
18563
0
SLANG_RAW("NV\";\n")
18564
0
SLANG_RAW("    case spirv:\n")
18565
0
SLANG_RAW("        {\n")
18566
0
SLANG_RAW("            if (__isFloat<T>())\n")
18567
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformF")
18568
0
SLANG_SPLICE(opName.name
18569
0
)
18570
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18571
0
SLANG_RAW("            else if (__isUnsignedInt<T>())\n")
18572
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformU")
18573
0
SLANG_SPLICE(opName.name
18574
0
)
18575
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18576
0
SLANG_RAW("            else\n")
18577
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformS")
18578
0
SLANG_SPLICE(opName.name
18579
0
)
18580
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18581
0
SLANG_RAW("        }\n")
18582
0
SLANG_RAW("    }\n")
18583
0
SLANG_RAW("}\n")
18584
0
SLANG_RAW("\n")
18585
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
18586
0
SLANG_RAW("__spirv_version(1.3)\n")
18587
0
SLANG_RAW("[ForceInline]\n")
18588
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18589
0
SLANG_RAW("vector<T, N> WaveMulti")
18590
0
SLANG_SPLICE(opName.name
18591
0
)
18592
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
18593
0
SLANG_RAW("{\n")
18594
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18595
0
SLANG_RAW("    __target_switch\n")
18596
0
SLANG_RAW("    {\n")
18597
0
SLANG_RAW("    case cuda:\n")
18598
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18599
0
SLANG_SPLICE(opName.name
18600
0
)
18601
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18602
0
SLANG_RAW("    case glsl:\n")
18603
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18604
0
SLANG_SPLICE(opName.name
18605
0
)
18606
0
SLANG_RAW("NV\";\n")
18607
0
SLANG_RAW("    case spirv:\n")
18608
0
SLANG_RAW("        {\n")
18609
0
SLANG_RAW("            if (__isFloat<T>())\n")
18610
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformF")
18611
0
SLANG_SPLICE(opName.name
18612
0
)
18613
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18614
0
SLANG_RAW("            else if (__isUnsignedInt<T>())\n")
18615
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformU")
18616
0
SLANG_SPLICE(opName.name
18617
0
)
18618
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18619
0
SLANG_RAW("            else\n")
18620
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformS")
18621
0
SLANG_SPLICE(opName.name
18622
0
)
18623
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask };\n")
18624
0
SLANG_RAW("        }\n")
18625
0
SLANG_RAW("    }\n")
18626
0
SLANG_RAW("}\n")
18627
0
SLANG_RAW("\n")
18628
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
18629
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18630
0
SLANG_RAW("matrix<T, N, M> WaveMulti")
18631
0
SLANG_SPLICE(opName.name
18632
0
)
18633
0
SLANG_RAW("(matrix<T, N, M> value, uint4 mask)\n")
18634
0
SLANG_RAW("{\n")
18635
0
SLANG_RAW("    __target_switch\n")
18636
0
SLANG_RAW("    {\n")
18637
0
SLANG_RAW("    case cuda:\n")
18638
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18639
0
SLANG_SPLICE(opName.name
18640
0
)
18641
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18642
0
SLANG_RAW("    default:\n")
18643
0
SLANG_RAW("        matrix<T, N, M> result;\n")
18644
0
SLANG_RAW("        [ForceUnroll]\n")
18645
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
18646
0
SLANG_RAW("            result[i] = WaveMulti")
18647
0
SLANG_SPLICE(opName.name
18648
0
)
18649
0
SLANG_RAW("(value[i], mask);\n")
18650
0
SLANG_RAW("        return result;\n")
18651
0
SLANG_RAW("    }\n")
18652
0
SLANG_RAW("}\n")
18653
0
SLANG_RAW("\n")
18654
18655
0
} // WaveMultiMin/WaveMultiMax.
18656
0
SLANG_RAW("#line 16827 \"hlsl.meta.slang\"")
18657
0
SLANG_RAW("\n")
18658
0
SLANG_RAW("\n")
18659
0
SLANG_RAW("\n")
18660
0
SLANG_RAW("//\n")
18661
0
SLANG_RAW("// WaveMultiPrefixInclusiveMin/WaveMultiPrefixInclusiveMax.\n")
18662
0
SLANG_RAW("// WaveMultiPrefixExclusiveMin/WaveMultiPrefixExclusiveMax.\n")
18663
0
SLANG_RAW("//\n")
18664
18665
0
struct WaveMultiPrefixMinMaxEntry
18666
0
{
18667
0
    const char* name;
18668
0
    const char* spirvName;
18669
0
    const char* spirvGroupOperation;
18670
0
    const char* glslName;
18671
0
};
18672
18673
0
const WaveMultiPrefixMinMaxEntry kWaveMultiPrefixMinMaxNames[] =
18674
0
{
18675
    // name             spirvName  spirvGroupOperation              glslName
18676
0
    { "InclusiveMin",   "Min",     "PartitionedInclusiveScanNV",    "InclusiveMin" },
18677
0
    { "InclusiveMax",   "Max",     "PartitionedInclusiveScanNV",    "InclusiveMax" },
18678
0
    { "ExclusiveMin",   "Min",     "PartitionedExclusiveScanNV",    "ExclusiveMin" },
18679
0
    { "ExclusiveMax",   "Max",     "PartitionedExclusiveScanNV",    "ExclusiveMax" },
18680
0
};
18681
18682
0
for (auto opName : kWaveMultiPrefixMinMaxNames) {
18683
0
SLANG_RAW("#line 16853 \"hlsl.meta.slang\"")
18684
0
SLANG_RAW("\n")
18685
0
SLANG_RAW("\n")
18686
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType>\n")
18687
0
SLANG_RAW("__spirv_version(1.3)\n")
18688
0
SLANG_RAW("[ForceInline]\n")
18689
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18690
0
SLANG_RAW("T WaveMultiPrefix")
18691
0
SLANG_SPLICE(opName.name
18692
0
)
18693
0
SLANG_RAW("(T value, uint4 mask)\n")
18694
0
SLANG_RAW("{\n")
18695
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18696
0
SLANG_RAW("    __target_switch\n")
18697
0
SLANG_RAW("    {\n")
18698
0
SLANG_RAW("    case glsl:\n")
18699
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18700
0
SLANG_SPLICE(opName.glslName
18701
0
)
18702
0
SLANG_RAW("NV\";\n")
18703
0
SLANG_RAW("    case cuda:\n")
18704
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18705
0
SLANG_SPLICE(opName.name
18706
0
)
18707
0
SLANG_RAW("(($1).x, $0)\";\n")
18708
0
SLANG_RAW("    case spirv:\n")
18709
0
SLANG_RAW("        {\n")
18710
0
SLANG_RAW("            if (__isFloat<T>())\n")
18711
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformF")
18712
0
SLANG_SPLICE(opName.spirvName
18713
0
)
18714
0
SLANG_RAW(" Subgroup ")
18715
0
SLANG_SPLICE(opName.spirvGroupOperation
18716
0
)
18717
0
SLANG_RAW(" $value $mask };\n")
18718
0
SLANG_RAW("            else if (__isUnsignedInt<T>())\n")
18719
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformU")
18720
0
SLANG_SPLICE(opName.spirvName
18721
0
)
18722
0
SLANG_RAW(" Subgroup ")
18723
0
SLANG_SPLICE(opName.spirvGroupOperation
18724
0
)
18725
0
SLANG_RAW(" $value $mask };\n")
18726
0
SLANG_RAW("            else\n")
18727
0
SLANG_RAW("                return spirv_asm { result:$$T = OpGroupNonUniformS")
18728
0
SLANG_SPLICE(opName.spirvName
18729
0
)
18730
0
SLANG_RAW(" Subgroup ")
18731
0
SLANG_SPLICE(opName.spirvGroupOperation
18732
0
)
18733
0
SLANG_RAW(" $value $mask };\n")
18734
0
SLANG_RAW("        }\n")
18735
0
SLANG_RAW("    }\n")
18736
0
SLANG_RAW("}\n")
18737
0
SLANG_RAW("\n")
18738
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
18739
0
SLANG_RAW("__spirv_version(1.3)\n")
18740
0
SLANG_RAW("[ForceInline]\n")
18741
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18742
0
SLANG_RAW("vector<T, N> WaveMultiPrefix")
18743
0
SLANG_SPLICE(opName.name
18744
0
)
18745
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
18746
0
SLANG_RAW("{\n")
18747
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18748
0
SLANG_RAW("    __target_switch\n")
18749
0
SLANG_RAW("    {\n")
18750
0
SLANG_RAW("    case glsl:\n")
18751
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18752
0
SLANG_SPLICE(opName.glslName
18753
0
)
18754
0
SLANG_RAW("NV\";\n")
18755
0
SLANG_RAW("    case cuda:\n")
18756
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18757
0
SLANG_SPLICE(opName.name
18758
0
)
18759
0
SLANG_RAW("Multiple(($1).x, $0)\";\n")
18760
0
SLANG_RAW("    case spirv:\n")
18761
0
SLANG_RAW("        {\n")
18762
0
SLANG_RAW("            if (__isFloat<T>())\n")
18763
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformF")
18764
0
SLANG_SPLICE(opName.spirvName
18765
0
)
18766
0
SLANG_RAW(" Subgroup ")
18767
0
SLANG_SPLICE(opName.spirvGroupOperation
18768
0
)
18769
0
SLANG_RAW(" $value $mask };\n")
18770
0
SLANG_RAW("            else if (__isUnsignedInt<T>())\n")
18771
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformU")
18772
0
SLANG_SPLICE(opName.spirvName
18773
0
)
18774
0
SLANG_RAW(" Subgroup ")
18775
0
SLANG_SPLICE(opName.spirvGroupOperation
18776
0
)
18777
0
SLANG_RAW(" $value $mask };\n")
18778
0
SLANG_RAW("            else\n")
18779
0
SLANG_RAW("                return spirv_asm { result:$$vector<T,N> = OpGroupNonUniformS")
18780
0
SLANG_SPLICE(opName.spirvName
18781
0
)
18782
0
SLANG_RAW(" Subgroup ")
18783
0
SLANG_SPLICE(opName.spirvGroupOperation
18784
0
)
18785
0
SLANG_RAW(" $value $mask };\n")
18786
0
SLANG_RAW("        }\n")
18787
0
SLANG_RAW("    }\n")
18788
0
SLANG_RAW("}\n")
18789
0
SLANG_RAW("\n")
18790
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int, let M : int>\n")
18791
0
SLANG_RAW("[require(glsl_spirv, subgroup_partitioned)]\n")
18792
0
SLANG_RAW("matrix<T, N, M> WaveMultiPrefix")
18793
0
SLANG_SPLICE(opName.name
18794
0
)
18795
0
SLANG_RAW("(matrix<T, N, M> value, uint4 mask)\n")
18796
0
SLANG_RAW("{\n")
18797
0
SLANG_RAW("    matrix<T, N, M> result;\n")
18798
0
SLANG_RAW("    [ForceUnroll]\n")
18799
0
SLANG_RAW("    for (int i = 0; i < N; ++i)\n")
18800
0
SLANG_RAW("        result[i] = WaveMultiPrefix")
18801
0
SLANG_SPLICE(opName.name
18802
0
)
18803
0
SLANG_RAW("(value[i], mask);\n")
18804
0
SLANG_RAW("    return result;\n")
18805
0
SLANG_RAW("}\n")
18806
0
SLANG_RAW("\n")
18807
18808
0
}
18809
// WaveMultiPrefixInclusiveMin/WaveMultiPrefixInclusiveMax.
18810
// WaveMultiPrefixExclusiveMin/WaveMultiPrefixExclusiveMax.
18811
0
SLANG_RAW("#line 16920 \"hlsl.meta.slang\"")
18812
0
SLANG_RAW("\n")
18813
0
SLANG_RAW("\n")
18814
0
SLANG_RAW("\n")
18815
0
SLANG_RAW("//\n")
18816
0
SLANG_RAW("// WaveMultiBitAnd/WaveMultiBitOr/WaveMultiBitXor.\n")
18817
0
SLANG_RAW("//\n")
18818
18819
0
struct WaveMultiBitsEntry { const char* name; };
18820
0
const WaveMultiBitsEntry kWaveMultiBitsNames[] = { {"And"}, {"Or"} , {"Xor"} };
18821
0
for (auto opName : kWaveMultiBitsNames) {
18822
0
SLANG_RAW("#line 16930 \"hlsl.meta.slang\"")
18823
0
SLANG_RAW("\n")
18824
0
SLANG_RAW("\n")
18825
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
18826
0
SLANG_RAW("__spirv_version(1.3)\n")
18827
0
SLANG_RAW("[ForceInline]\n")
18828
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18829
0
SLANG_RAW("T WaveMultiBit")
18830
0
SLANG_SPLICE(opName.name
18831
0
)
18832
0
SLANG_RAW("(T value, uint4 mask)\n")
18833
0
SLANG_RAW("{\n")
18834
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18835
0
SLANG_RAW("    __target_switch\n")
18836
0
SLANG_RAW("    {\n")
18837
0
SLANG_RAW("    case cuda:\n")
18838
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18839
0
SLANG_SPLICE(opName.name
18840
0
)
18841
0
SLANG_RAW("($1.x, $0)\";\n")
18842
0
SLANG_RAW("    case glsl:\n")
18843
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18844
0
SLANG_SPLICE(opName.name
18845
0
)
18846
0
SLANG_RAW("NV\";\n")
18847
0
SLANG_RAW("    case spirv:\n")
18848
0
SLANG_RAW("        return spirv_asm\n")
18849
0
SLANG_RAW("        {\n")
18850
0
SLANG_RAW("            result:$$T = OpGroupNonUniformBitwise")
18851
0
SLANG_SPLICE(opName.name
18852
0
)
18853
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask;\n")
18854
0
SLANG_RAW("        };\n")
18855
0
SLANG_RAW("    }\n")
18856
0
SLANG_RAW("}\n")
18857
0
SLANG_RAW("\n")
18858
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
18859
0
SLANG_RAW("__spirv_version(1.3)\n")
18860
0
SLANG_RAW("[ForceInline]\n")
18861
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18862
0
SLANG_RAW("vector<T, N> WaveMultiBit")
18863
0
SLANG_SPLICE(opName.name
18864
0
)
18865
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
18866
0
SLANG_RAW("{\n")
18867
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18868
0
SLANG_RAW("    __target_switch\n")
18869
0
SLANG_RAW("    {\n")
18870
0
SLANG_RAW("    case cuda:\n")
18871
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18872
0
SLANG_SPLICE(opName.name
18873
0
)
18874
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18875
0
SLANG_RAW("    case glsl:\n")
18876
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18877
0
SLANG_SPLICE(opName.name
18878
0
)
18879
0
SLANG_RAW("NV\";\n")
18880
0
SLANG_RAW("    case spirv:\n")
18881
0
SLANG_RAW("        return spirv_asm\n")
18882
0
SLANG_RAW("        {\n")
18883
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformBitwise")
18884
0
SLANG_SPLICE(opName.name
18885
0
)
18886
0
SLANG_RAW(" Subgroup PartitionedReduceNV $value $mask;\n")
18887
0
SLANG_RAW("        };\n")
18888
0
SLANG_RAW("    }\n")
18889
0
SLANG_RAW("}\n")
18890
0
SLANG_RAW("\n")
18891
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
18892
0
SLANG_RAW("[require(cuda_glsl_spirv, subgroup_partitioned)]\n")
18893
0
SLANG_RAW("matrix<T, N, M> WaveMultiBit")
18894
0
SLANG_SPLICE(opName.name
18895
0
)
18896
0
SLANG_RAW("(matrix<T, N, M> value, uint4 mask)\n")
18897
0
SLANG_RAW("{\n")
18898
0
SLANG_RAW("    __target_switch\n")
18899
0
SLANG_RAW("    {\n")
18900
0
SLANG_RAW("    case cuda:\n")
18901
0
SLANG_RAW("        __intrinsic_asm \"_wave")
18902
0
SLANG_SPLICE(opName.name
18903
0
)
18904
0
SLANG_RAW("Multiple($1.x, $0)\";\n")
18905
0
SLANG_RAW("    default:\n")
18906
0
SLANG_RAW("        matrix<T,N,M> result;\n")
18907
0
SLANG_RAW("        [ForceUnroll]\n")
18908
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
18909
0
SLANG_RAW("            result[i] = WaveMultiBit")
18910
0
SLANG_SPLICE(opName.name
18911
0
)
18912
0
SLANG_RAW("(value[i], mask);\n")
18913
0
SLANG_RAW("        return result;\n")
18914
0
SLANG_RAW("    }\n")
18915
0
SLANG_RAW("}\n")
18916
0
SLANG_RAW("\n")
18917
18918
0
} // WaveMultiBitAnd/WaveMultiBitOr/WaveMultiBitXor.
18919
0
SLANG_RAW("#line 16993 \"hlsl.meta.slang\"")
18920
0
SLANG_RAW("\n")
18921
0
SLANG_RAW("\n")
18922
0
SLANG_RAW("\n")
18923
0
SLANG_RAW("//\n")
18924
0
SLANG_RAW("// WaveMultiPrefixInclusiveBitAnd/WaveMultiPrefixInclusiveBitOr/WaveMultiInclusiveBitXor.\n")
18925
0
SLANG_RAW("// WaveMultiPrefixExclusiveBitAnd/WaveMultiPrefixExclusiveBitXor/WaveMultiExclusiveBitXor.\n")
18926
0
SLANG_RAW("// WaveMultiPrefixBitAnd/WaveMultiPrefixBitOr/WaveMultiBitXor.\n")
18927
0
SLANG_RAW("//\n")
18928
18929
0
struct WaveMultiPrefixBitwiseEntry
18930
0
{
18931
0
    const char* name;
18932
0
    const char* spirvName;
18933
0
    const char* spirvGroupOperation;
18934
0
    const char* glslName;
18935
0
    const char* hlslName;
18936
0
    const char* cudaExtraOperation;
18937
18938
0
    bool cudaMatrixVariantSupport;
18939
0
};
18940
18941
0
const WaveMultiPrefixBitwiseEntry kWaveMultiPrefixBitwiseNames[] =
18942
0
{
18943
    // name           spirvName     spirvGroupOperation            glslName       hlslName              cudaExtraOperation  cudaMatrixVariantSupport
18944
0
    { "InclusiveBitAnd", "And",     "PartitionedInclusiveScanNV", "InclusiveAnd", "And($0, $1) & $0",      "& $0",          false },
18945
0
    { "InclusiveBitOr",  "Or",      "PartitionedInclusiveScanNV", "InclusiveOr",  "Or($0, $1) | $0",       "| $0",          false },
18946
0
    { "InclusiveBitXor", "Xor",     "PartitionedInclusiveScanNV", "InclusiveXor", "Xor($0, $1) ^ $0",      "^ $0",          false },
18947
0
    { "ExclusiveBitAnd", "And",     "PartitionedExclusiveScanNV", "ExclusiveAnd", "And",                  "",               true  },
18948
0
    { "ExclusiveBitOr",  "Or",      "PartitionedExclusiveScanNV", "ExclusiveOr",  "Or",                   "",               true  },
18949
0
    { "ExclusiveBitXor", "Xor",     "PartitionedExclusiveScanNV", "ExclusiveXor", "Xor",                  "",               true  },
18950
18951
    // These are HLSL SM 6.5 intrinsics and are equal to the exclusive variants.
18952
0
    { "BitAnd",          "And",     "PartitionedExclusiveScanNV", "ExclusiveAnd", "And",                  "",               true  },
18953
0
    { "BitOr",           "Or",      "PartitionedExclusiveScanNV", "ExclusiveOr",  "Or",                   "",               true  },
18954
0
    { "BitXor",          "Xor",     "PartitionedExclusiveScanNV", "ExclusiveXor", "Xor",                  "",               true  },
18955
0
};
18956
18957
0
for (auto opName : kWaveMultiPrefixBitwiseNames) {
18958
0
SLANG_RAW("#line 17031 \"hlsl.meta.slang\"")
18959
0
SLANG_RAW("\n")
18960
0
SLANG_RAW("\n")
18961
0
SLANG_RAW("__generic<T : __BuiltinLogicalType>\n")
18962
0
SLANG_RAW("__spirv_version(1.3)\n")
18963
0
SLANG_RAW("[ForceInline]\n")
18964
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
18965
0
SLANG_RAW("T WaveMultiPrefix")
18966
0
SLANG_SPLICE(opName.name
18967
0
)
18968
0
SLANG_RAW("(T value, uint4 mask)\n")
18969
0
SLANG_RAW("{\n")
18970
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
18971
0
SLANG_RAW("    __target_switch\n")
18972
0
SLANG_RAW("    {\n")
18973
0
SLANG_RAW("    case cuda:\n")
18974
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
18975
0
SLANG_SPLICE(opName.spirvName
18976
0
)
18977
0
SLANG_RAW("($1.x, $0) ")
18978
0
SLANG_SPLICE(opName.cudaExtraOperation
18979
0
)
18980
0
SLANG_RAW("\";\n")
18981
0
SLANG_RAW("    case glsl:\n")
18982
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
18983
0
SLANG_SPLICE(opName.glslName
18984
0
)
18985
0
SLANG_RAW("NV\";\n")
18986
0
SLANG_RAW("    case hlsl:\n")
18987
0
SLANG_RAW("        __intrinsic_asm \"WaveMultiPrefixBit")
18988
0
SLANG_SPLICE(opName.hlslName
18989
0
)
18990
0
SLANG_RAW("\";\n")
18991
0
SLANG_RAW("    case spirv:\n")
18992
0
SLANG_RAW("        return spirv_asm\n")
18993
0
SLANG_RAW("        {\n")
18994
0
SLANG_RAW("            result:$$T = OpGroupNonUniformBitwise")
18995
0
SLANG_SPLICE(opName.spirvName
18996
0
)
18997
0
SLANG_RAW(" Subgroup ")
18998
0
SLANG_SPLICE(opName.spirvGroupOperation
18999
0
)
19000
0
SLANG_RAW(" $value $mask;\n")
19001
0
SLANG_RAW("        };\n")
19002
0
SLANG_RAW("    }\n")
19003
0
SLANG_RAW("}\n")
19004
0
SLANG_RAW("\n")
19005
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int>\n")
19006
0
SLANG_RAW("__spirv_version(1.3)\n")
19007
0
SLANG_RAW("[ForceInline]\n")
19008
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
19009
0
SLANG_RAW("vector<T, N> WaveMultiPrefix")
19010
0
SLANG_SPLICE(opName.name
19011
0
)
19012
0
SLANG_RAW("(vector<T, N> value, uint4 mask)\n")
19013
0
SLANG_RAW("{\n")
19014
0
SLANG_RAW("    __shaderSubgroupPartitionedPreamble<T>();\n")
19015
0
SLANG_RAW("    __target_switch\n")
19016
0
SLANG_RAW("    {\n")
19017
0
SLANG_RAW("    case cuda:\n")
19018
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
19019
0
SLANG_SPLICE(opName.spirvName
19020
0
)
19021
0
SLANG_RAW("Multiple($1.x, $0) ")
19022
0
SLANG_SPLICE(opName.cudaExtraOperation
19023
0
)
19024
0
SLANG_RAW("\";\n")
19025
0
SLANG_RAW("    case glsl:\n")
19026
0
SLANG_RAW("        __intrinsic_asm \"subgroupPartitioned")
19027
0
SLANG_SPLICE(opName.glslName
19028
0
)
19029
0
SLANG_RAW("NV\";\n")
19030
0
SLANG_RAW("    case hlsl:\n")
19031
0
SLANG_RAW("        __intrinsic_asm \"WaveMultiPrefixBit")
19032
0
SLANG_SPLICE(opName.hlslName
19033
0
)
19034
0
SLANG_RAW("\";\n")
19035
0
SLANG_RAW("    case spirv:\n")
19036
0
SLANG_RAW("        return spirv_asm\n")
19037
0
SLANG_RAW("        {\n")
19038
0
SLANG_RAW("            result:$$vector<T,N> = OpGroupNonUniformBitwise")
19039
0
SLANG_SPLICE(opName.spirvName
19040
0
)
19041
0
SLANG_RAW(" Subgroup ")
19042
0
SLANG_SPLICE(opName.spirvGroupOperation
19043
0
)
19044
0
SLANG_RAW(" $value $mask;\n")
19045
0
SLANG_RAW("        };\n")
19046
0
SLANG_RAW("    }\n")
19047
0
SLANG_RAW("}\n")
19048
0
SLANG_RAW("\n")
19049
0
SLANG_RAW("__generic<T : __BuiltinLogicalType, let N : int, let M : int>\n")
19050
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, subgroup_partitioned)]\n")
19051
0
SLANG_RAW("matrix<T, N, M> WaveMultiPrefix")
19052
0
SLANG_SPLICE(opName.name
19053
0
)
19054
0
SLANG_RAW("(matrix<T, N, M> value, uint4 mask)\n")
19055
0
SLANG_RAW("{\n")
19056
0
SLANG_RAW("    __target_switch\n")
19057
0
SLANG_RAW("    {\n")
19058
19059
0
    if (opName.cudaMatrixVariantSupport) {
19060
0
SLANG_RAW("#line 17087 \"hlsl.meta.slang\"")
19061
0
SLANG_RAW("\n")
19062
0
SLANG_RAW("    case cuda:\n")
19063
0
SLANG_RAW("        __intrinsic_asm \"_wavePrefix")
19064
0
SLANG_SPLICE(opName.spirvName
19065
0
)
19066
0
SLANG_RAW("Multiple($1.x, $0) ")
19067
0
SLANG_SPLICE(opName.cudaExtraOperation
19068
0
)
19069
0
SLANG_RAW("\";\n")
19070
19071
0
    }
19072
0
SLANG_RAW("#line 17092 \"hlsl.meta.slang\"")
19073
0
SLANG_RAW("\n")
19074
0
SLANG_RAW("    default:\n")
19075
0
SLANG_RAW("        matrix<T,N,M> result;\n")
19076
0
SLANG_RAW("        [ForceUnroll]\n")
19077
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
19078
0
SLANG_RAW("            result[i] = WaveMultiPrefix")
19079
0
SLANG_SPLICE(opName.name
19080
0
)
19081
0
SLANG_RAW("(value[i], mask);\n")
19082
0
SLANG_RAW("        return result;\n")
19083
0
SLANG_RAW("    }\n")
19084
0
SLANG_RAW("}\n")
19085
19086
0
}
19087
// WaveMultiPrefixInclusiveBitAnd/WaveMultiPrefixInclusiveBitOr/WaveMultiInclusiveBitXor.
19088
// WaveMultiPrefixExclusiveBitAnd/WaveMultiPrefixExclusiveBitXor/WaveMultiExclusiveBitXor.
19089
// WaveMultiPrefixBitAnd/WaveMultiPrefixBitOr/WaveMultiBitXor.
19090
0
SLANG_RAW("#line 17106 \"hlsl.meta.slang\"")
19091
0
SLANG_RAW("\n")
19092
0
SLANG_RAW("\n")
19093
0
SLANG_RAW("\n")
19094
0
SLANG_RAW("//\n")
19095
0
SLANG_RAW("// Quad Control intrinsics\n")
19096
0
SLANG_RAW("//\n")
19097
0
SLANG_RAW("// For SPIRV and GLSL targets, the behavior is taken from Vulkan's `VK_KHR_shader_quad_control` spec.\n")
19098
0
SLANG_RAW("// QuadAny/QuadAll will map to OpGroupNonUniformQuadAny/All, and using either of these functions will\n")
19099
0
SLANG_RAW("// result in the QuadDerivativesKHR execution mode being used. If MaximallyReconvergesKHR is not already\n")
19100
0
SLANG_RAW("// specified by other means, it will be added when using either of QuadAny/QuadAll,\n")
19101
0
SLANG_RAW("//\n")
19102
0
SLANG_RAW("\n")
19103
0
SLANG_RAW("//@public:\n")
19104
0
SLANG_RAW("/// Returns true if `expr` is true in any lane of the current quad.\n")
19105
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
19106
0
SLANG_RAW("__glsl_extension(GL_EXT_maximal_reconvergence)\n")
19107
0
SLANG_RAW("__glsl_extension(GL_EXT_shader_quad_control)\n")
19108
0
SLANG_RAW("__spirv_version(1.3)\n")
19109
0
SLANG_RAW("[ForceInline]\n")
19110
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, quad_control)]\n")
19111
0
SLANG_RAW("bool QuadAny(bool expr)\n")
19112
0
SLANG_RAW("{\n")
19113
0
SLANG_RAW("    __requireMaximallyReconverges();\n")
19114
0
SLANG_RAW("    __requireQuadDerivatives();\n")
19115
0
SLANG_RAW("    __target_switch\n")
19116
0
SLANG_RAW("    {\n")
19117
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadAny\";\n")
19118
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadAny\";\n")
19119
0
SLANG_RAW("    case metal: __intrinsic_asm \"quad_any\";\n")
19120
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_slang_quadAny\";\n")
19121
0
SLANG_RAW("    case spirv:\n")
19122
0
SLANG_RAW("        return spirv_asm\n")
19123
0
SLANG_RAW("        {\n")
19124
0
SLANG_RAW("            result:$$bool = OpGroupNonUniformQuadAnyKHR $expr;\n")
19125
0
SLANG_RAW("        };\n")
19126
0
SLANG_RAW("    }\n")
19127
0
SLANG_RAW("}\n")
19128
0
SLANG_RAW("\n")
19129
0
SLANG_RAW("//@public:\n")
19130
0
SLANG_RAW("/// Returns true if `expr` is true in all lanes of the current quad.\n")
19131
0
SLANG_RAW("__glsl_extension(GL_KHR_shader_subgroup_vote)\n")
19132
0
SLANG_RAW("__glsl_extension(GL_EXT_maximal_reconvergence)\n")
19133
0
SLANG_RAW("__glsl_extension(GL_EXT_shader_quad_control)\n")
19134
0
SLANG_RAW("__spirv_version(1.3)\n")
19135
0
SLANG_RAW("[ForceInline]\n")
19136
0
SLANG_RAW("[require(cuda_glsl_hlsl_metal_spirv, quad_control)]\n")
19137
0
SLANG_RAW("bool QuadAll(bool expr)\n")
19138
0
SLANG_RAW("{\n")
19139
0
SLANG_RAW("    __requireMaximallyReconverges();\n")
19140
0
SLANG_RAW("    __requireQuadDerivatives();\n")
19141
0
SLANG_RAW("    __target_switch\n")
19142
0
SLANG_RAW("    {\n")
19143
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"QuadAll\";\n")
19144
0
SLANG_RAW("    case glsl: __intrinsic_asm \"subgroupQuadAll\";\n")
19145
0
SLANG_RAW("    case metal: __intrinsic_asm \"quad_all\";\n")
19146
0
SLANG_RAW("    case cuda: __intrinsic_asm \"_slang_quadAll\";\n")
19147
0
SLANG_RAW("    case spirv:\n")
19148
0
SLANG_RAW("        return spirv_asm\n")
19149
0
SLANG_RAW("        {\n")
19150
0
SLANG_RAW("            result:$$bool = OpGroupNonUniformQuadAllKHR $expr;\n")
19151
0
SLANG_RAW("        };\n")
19152
0
SLANG_RAW("    }\n")
19153
0
SLANG_RAW("}\n")
19154
0
SLANG_RAW("\n")
19155
0
SLANG_RAW("// `typedef`s to help with the fact that HLSL has been sorta-kinda case insensitive at various points\n")
19156
0
SLANG_RAW("//@hidden:\n")
19157
0
SLANG_RAW("typedef Texture2D texture2D;\n")
19158
0
SLANG_RAW("//@public:\n")
19159
0
SLANG_RAW("\n")
19160
19161
19162
// Buffer types
19163
19164
0
static const struct {
19165
0
    char const*         name;
19166
0
    SlangResourceAccess access;
19167
0
} kBaseBufferAccessLevels[] = {
19168
0
    { "",                   SLANG_RESOURCE_ACCESS_READ },
19169
0
    { "RW",                 SLANG_RESOURCE_ACCESS_READ_WRITE },
19170
0
    { "RasterizerOrdered",  SLANG_RESOURCE_ACCESS_RASTER_ORDERED },
19171
0
};
19172
0
static const int kBaseBufferAccessLevelCount = sizeof(kBaseBufferAccessLevels) / sizeof(kBaseBufferAccessLevels[0]);
19173
19174
0
for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
19175
0
{
19176
0
    auto access = kBaseBufferAccessLevels[aa].access;
19177
0
    sb << "/// @category texture_types\n";
19178
0
    sb << "__generic<T:ITexelElement,let format:int=0>\n";
19179
0
    sb << "typealias ";
19180
0
    sb << kBaseBufferAccessLevels[aa].name;
19181
0
    sb << "Buffer = _Texture<T, __ShapeBuffer, 0, 0, 0, " << aa << ", 0, 0, format>;\n";
19182
19183
0
    bool isReadOnly = aa == 0;
19184
19185
0
    char const* glslTextureSizeFunc = (isReadOnly) ? "textureSize" : "imageSize";
19186
0
    char const* glslLoadFuncName = (isReadOnly) ? "texelFetch" : "imageLoad";
19187
0
    char const* spvLoadInstName = (isReadOnly) ? "OpImageFetch" : "OpImageRead";
19188
0
    char const* requireToSetQuery = (isReadOnly) ? "[require(glsl_hlsl_metal_spirv, texture_size)]" : "[require(glsl_hlsl_metal_spirv, image_size)]";
19189
0
    char const* requireToSet = (isReadOnly) ? "[require(glsl_hlsl_metal_spirv, texture_sm_4_1)]" : "[require(glsl_hlsl_metal_spirv, texture_sm_4_1_compute_fragment)]";
19190
0
    char const* requireToSet_onlyHLSL = (isReadOnly) ? "[require(hlsl, texture_sm_4_1)]" : "[require(hlsl, texture_sm_4_1_compute_fragment)]";
19191
0
SLANG_RAW("#line 17206 \"hlsl.meta.slang\"")
19192
0
SLANG_RAW("\n")
19193
0
SLANG_RAW("\n")
19194
0
SLANG_RAW("__generic<T:ITexelElement, let format:int>\n")
19195
0
SLANG_RAW("extension _Texture<T, __ShapeBuffer, 0, 0, 0, ")
19196
0
SLANG_SPLICE(aa
19197
0
)
19198
0
SLANG_RAW(", 0, 0, format>\n")
19199
0
SLANG_RAW("{\n")
19200
0
SLANG_RAW("    [__readNone]\n")
19201
0
SLANG_RAW("    ")
19202
0
SLANG_SPLICE(requireToSetQuery
19203
0
)
19204
0
SLANG_RAW("\n")
19205
0
SLANG_RAW("    void GetDimensions(out uint dim)\n")
19206
0
SLANG_RAW("    {\n")
19207
0
SLANG_RAW("        __target_switch\n")
19208
0
SLANG_RAW("        {\n")
19209
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetDimensions\";\n")
19210
0
SLANG_RAW("        case glsl:\n")
19211
0
SLANG_RAW("            __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
19212
0
SLANG_RAW("            __intrinsic_asm \"($1 = ")
19213
0
SLANG_SPLICE(glslTextureSizeFunc
19214
0
)
19215
0
SLANG_RAW("($0))\";\n")
19216
0
SLANG_RAW("        case metal: __intrinsic_asm \"(*($1) = $0.get_width())\";\n")
19217
0
SLANG_RAW("        case spirv:\n")
19218
0
SLANG_RAW("            dim = spirv_asm {\n")
19219
0
SLANG_RAW("                OpCapability ImageQuery;\n")
19220
0
SLANG_RAW("                result:$$uint = OpImageQuerySize $this;\n")
19221
0
SLANG_RAW("            };\n")
19222
0
SLANG_RAW("        }\n")
19223
0
SLANG_RAW("    }\n")
19224
0
SLANG_RAW("\n")
19225
0
SLANG_RAW("    ")
19226
0
SLANG_SPLICE(isReadOnly?"[__readNone] ":""
19227
0
)
19228
0
SLANG_RAW("\n")
19229
0
SLANG_RAW("    ")
19230
0
SLANG_SPLICE(requireToSet
19231
0
)
19232
0
SLANG_RAW("\n")
19233
0
SLANG_RAW("    T Load(int location)\n")
19234
0
SLANG_RAW("    {\n")
19235
0
SLANG_RAW("        __target_switch\n")
19236
0
SLANG_RAW("        {\n")
19237
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
19238
0
SLANG_RAW("        case metal: __intrinsic_asm \"$c$0.read(uint($1))$z\";\n")
19239
0
SLANG_RAW("        case glsl:\n")
19240
0
SLANG_RAW("            __requireTargetExtension(\"GL_EXT_samplerless_texture_functions\");\n")
19241
0
SLANG_RAW("            __intrinsic_asm \"")
19242
0
SLANG_SPLICE(glslLoadFuncName
19243
0
)
19244
0
SLANG_RAW("($0, $1)$z\";\n")
19245
0
SLANG_RAW("        case spirv: return spirv_asm {\n")
19246
0
SLANG_RAW("                %sampled:__sampledType(T) = ")
19247
0
SLANG_SPLICE(spvLoadInstName
19248
0
)
19249
0
SLANG_RAW(" $this $location;\n")
19250
0
SLANG_RAW("                __truncate $$T result __sampledType(T) %sampled;\n")
19251
0
SLANG_RAW("            };\n")
19252
0
SLANG_RAW("        }\n")
19253
0
SLANG_RAW("    }\n")
19254
0
SLANG_RAW("\n")
19255
0
SLANG_RAW("    ")
19256
0
SLANG_SPLICE(isReadOnly?"[__readNone] ":""
19257
0
)
19258
0
SLANG_RAW("\n")
19259
0
SLANG_RAW("    ")
19260
0
SLANG_SPLICE(requireToSet_onlyHLSL
19261
0
)
19262
0
SLANG_RAW("\n")
19263
0
SLANG_RAW("    T Load(int location, out uint status)\n")
19264
0
SLANG_RAW("    {\n")
19265
0
SLANG_RAW("        __target_switch\n")
19266
0
SLANG_RAW("        {\n")
19267
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Load\";\n")
19268
0
SLANG_RAW("        }\n")
19269
0
SLANG_RAW("    }\n")
19270
0
SLANG_RAW("\n")
19271
0
SLANG_RAW("    __subscript(uint index) -> T {\n")
19272
0
SLANG_RAW("\n")
19273
0
SLANG_RAW("        ")
19274
0
SLANG_SPLICE(isReadOnly?"[__readNone] ":""
19275
0
)
19276
0
SLANG_RAW("\n")
19277
0
SLANG_RAW("        [ForceInline]\n")
19278
0
SLANG_RAW("        ")
19279
0
SLANG_SPLICE(requireToSet
19280
0
)
19281
0
SLANG_RAW("\n")
19282
0
SLANG_RAW("        get { return Load((int)index); }\n")
19283
19284
0
        if (access != SLANG_RESOURCE_ACCESS_READ) {
19285
0
SLANG_RAW("#line 17266 \"hlsl.meta.slang\"")
19286
0
SLANG_RAW("\n")
19287
0
SLANG_RAW("            [nonmutating]\n")
19288
0
SLANG_RAW("            ")
19289
0
SLANG_SPLICE(requireToSet
19290
0
)
19291
0
SLANG_RAW("\n")
19292
0
SLANG_RAW("            set\n")
19293
0
SLANG_RAW("            {\n")
19294
0
SLANG_RAW("                __target_switch\n")
19295
0
SLANG_RAW("                {\n")
19296
0
SLANG_RAW("                case hlsl: __intrinsic_asm \"($0)[$1] = $2\";\n")
19297
0
SLANG_RAW("                case glsl: __intrinsic_asm \"imageStore($0, int($1), $V2)\";\n")
19298
0
SLANG_RAW("                case metal: __intrinsic_asm \"$0.write($2, $1)\";\n")
19299
0
SLANG_RAW("                case spirv: spirv_asm {\n")
19300
0
SLANG_RAW("                        OpImageWrite $this $index __convertTexel(newValue);\n")
19301
0
SLANG_RAW("                    };\n")
19302
0
SLANG_RAW("                }\n")
19303
0
SLANG_RAW("            }\n")
19304
0
SLANG_RAW("\n")
19305
0
SLANG_RAW("            // If a 'Texture[index]' is referred to by a '__ref', call 'kIROp_ImageSubscript(index)'.\n")
19306
0
SLANG_RAW("            // This allows call's to stay aware that the input is from a 'Texture'.\n")
19307
0
SLANG_RAW("            __intrinsic_op(")
19308
0
SLANG_SPLICE(kIROp_ImageSubscript
19309
0
)
19310
0
SLANG_RAW(")\n")
19311
0
SLANG_RAW("            [nonmutating]\n")
19312
0
SLANG_RAW("            ref;\n")
19313
19314
0
        } // access != SLANG_RESOURCE_ACCESS_READ
19315
0
SLANG_RAW("#line 17289 \"hlsl.meta.slang\"")
19316
0
SLANG_RAW("\n")
19317
0
SLANG_RAW("\n")
19318
0
SLANG_RAW("        }\n")
19319
0
SLANG_RAW("\n")
19320
0
SLANG_RAW("\n")
19321
0
SLANG_RAW("    };  // end extension\n")
19322
19323
0
}
19324
0
SLANG_RAW("#line 17297 \"hlsl.meta.slang\"")
19325
0
SLANG_RAW("\n")
19326
0
SLANG_RAW("\n")
19327
0
SLANG_RAW("\n")
19328
0
SLANG_RAW("// DirectX Raytracing (DXR) Support\n")
19329
0
SLANG_RAW("//\n")
19330
0
SLANG_RAW("// The following is based on the experimental DXR SDK v0.09.01.\n")
19331
0
SLANG_RAW("//\n")
19332
0
SLANG_RAW("// Numbering follows the sections in the \"D3D12 Raytracing Functional Spec\" v0.09 (2018-03-12)\n")
19333
0
SLANG_RAW("//\n")
19334
0
SLANG_RAW("\n")
19335
0
SLANG_RAW("// 10.1.1 - Ray Flags\n")
19336
0
SLANG_RAW("\n")
19337
0
SLANG_RAW("/// Flags that control ray traversal behavior and shader execution.\n")
19338
0
SLANG_RAW("/// @category raytracing\n")
19339
0
SLANG_RAW("typedef uint RAY_FLAG;\n")
19340
0
SLANG_RAW("\n")
19341
0
SLANG_RAW("/// No special ray flags.\n")
19342
0
SLANG_RAW("/// @category raytracing\n")
19343
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_NONE = 0x00;\n")
19344
0
SLANG_RAW("\n")
19345
0
SLANG_RAW("/// Forces all geometries to be treated as opaque, disabling any-hit shader execution.\n")
19346
0
SLANG_RAW("/// @category raytracing\n")
19347
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_FORCE_OPAQUE = 0x01;\n")
19348
0
SLANG_RAW("\n")
19349
0
SLANG_RAW("/// Forces all geometries to be treated as non-opaque, enabling any-hit shader execution.\n")
19350
0
SLANG_RAW("/// @category raytracing\n")
19351
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_FORCE_NON_OPAQUE = 0x02;\n")
19352
0
SLANG_RAW("\n")
19353
0
SLANG_RAW("/// Accepts the first intersection found and skips searching for closer hits.\n")
19354
0
SLANG_RAW("/// @category raytracing\n")
19355
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH = 0x04;\n")
19356
0
SLANG_RAW("\n")
19357
0
SLANG_RAW("/// Skips execution of closest hit shaders, useful for shadow rays.\n")
19358
0
SLANG_RAW("/// @category raytracing\n")
19359
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_SKIP_CLOSEST_HIT_SHADER = 0x08;\n")
19360
0
SLANG_RAW("\n")
19361
0
SLANG_RAW("/// Culls triangles facing away from the ray origin.\n")
19362
0
SLANG_RAW("/// @category raytracing\n")
19363
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_CULL_BACK_FACING_TRIANGLES = 0x10;\n")
19364
0
SLANG_RAW("\n")
19365
0
SLANG_RAW("/// Culls triangles facing toward the ray origin.\n")
19366
0
SLANG_RAW("/// @category raytracing\n")
19367
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_CULL_FRONT_FACING_TRIANGLES = 0x20;\n")
19368
0
SLANG_RAW("\n")
19369
0
SLANG_RAW("/// Skips intersections with opaque geometry.\n")
19370
0
SLANG_RAW("/// @category raytracing\n")
19371
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_CULL_OPAQUE = 0x40;\n")
19372
0
SLANG_RAW("\n")
19373
0
SLANG_RAW("/// Skips intersections with non-opaque geometry.\n")
19374
0
SLANG_RAW("/// @category raytracing\n")
19375
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_CULL_NON_OPAQUE = 0x80;\n")
19376
0
SLANG_RAW("\n")
19377
0
SLANG_RAW("/// Skips all triangle intersections.\n")
19378
0
SLANG_RAW("/// @category raytracing\n")
19379
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_SKIP_TRIANGLES = 0x100;\n")
19380
0
SLANG_RAW("\n")
19381
0
SLANG_RAW("/// Skips all procedural primitive intersections.\n")
19382
0
SLANG_RAW("/// @category raytracing\n")
19383
0
SLANG_RAW("static const RAY_FLAG RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES = 0x200;\n")
19384
0
SLANG_RAW("\n")
19385
0
SLANG_RAW("// 10.1.2 - Ray Description Structure\n")
19386
0
SLANG_RAW("/// Describes a ray for traversal through an acceleration structure.\n")
19387
0
SLANG_RAW("/// @category raytracing\n")
19388
0
SLANG_RAW("__target_intrinsic(hlsl, RayDesc)\n")
19389
0
SLANG_RAW("__target_intrinsic(cuda, RayDesc)\n")
19390
0
SLANG_RAW("struct RayDesc\n")
19391
0
SLANG_RAW("{\n")
19392
0
SLANG_RAW("    /// Starting point of the ray in world space.\n")
19393
0
SLANG_RAW("    __target_intrinsic(hlsl, Origin)\n")
19394
0
SLANG_RAW("    __target_intrinsic(cuda, Origin)\n")
19395
0
SLANG_RAW("    float3 Origin;\n")
19396
0
SLANG_RAW("\n")
19397
0
SLANG_RAW("    /// Minimum distance along the ray to consider intersections.\n")
19398
0
SLANG_RAW("    __target_intrinsic(hlsl, TMin)\n")
19399
0
SLANG_RAW("    __target_intrinsic(cuda, TMin)\n")
19400
0
SLANG_RAW("    float  TMin;\n")
19401
0
SLANG_RAW("\n")
19402
0
SLANG_RAW("    /// Normalized direction vector of the ray in world space.\n")
19403
0
SLANG_RAW("    __target_intrinsic(hlsl, Direction)\n")
19404
0
SLANG_RAW("    __target_intrinsic(cuda, Direction)\n")
19405
0
SLANG_RAW("    float3 Direction;\n")
19406
0
SLANG_RAW("\n")
19407
0
SLANG_RAW("    /// Maximum distance along the ray to consider intersections.\n")
19408
0
SLANG_RAW("    __target_intrinsic(hlsl, TMax)\n")
19409
0
SLANG_RAW("    __target_intrinsic(cuda, TMax)\n")
19410
0
SLANG_RAW("    float  TMax;\n")
19411
0
SLANG_RAW("};\n")
19412
0
SLANG_RAW("\n")
19413
0
SLANG_RAW("// 10.1.3 - Ray Acceleration Structure\n")
19414
0
SLANG_RAW("/// Opaque type representing a ray-tracing acceleration structure.\n")
19415
0
SLANG_RAW("/// @category raytracing\n")
19416
0
SLANG_RAW("__builtin\n")
19417
0
SLANG_RAW("__magic_type(RaytracingAccelerationStructureType)\n")
19418
0
SLANG_RAW("__intrinsic_type(")
19419
0
SLANG_SPLICE(kIROp_RaytracingAccelerationStructureType
19420
0
)
19421
0
SLANG_RAW(")\n")
19422
0
SLANG_RAW("struct RaytracingAccelerationStructure\n")
19423
0
SLANG_RAW("{\n")
19424
0
SLANG_RAW("    [require(glsl_spirv, raytracing)]\n")
19425
0
SLANG_RAW("    [__readNone]\n")
19426
0
SLANG_RAW("    __init(uint64_t address)\n")
19427
0
SLANG_RAW("    {\n")
19428
0
SLANG_RAW("        __target_switch\n")
19429
0
SLANG_RAW("        {\n")
19430
0
SLANG_RAW("        case spirv:\n")
19431
0
SLANG_RAW("            return spirv_asm {\n")
19432
0
SLANG_RAW("                result: $$RaytracingAccelerationStructure = OpConvertUToAccelerationStructureKHR $address;\n")
19433
0
SLANG_RAW("            };\n")
19434
0
SLANG_RAW("        case glsl:\n")
19435
0
SLANG_RAW("            __intrinsic_asm \"accelerationStructureEXT($0)\";\n")
19436
0
SLANG_RAW("        }\n")
19437
0
SLANG_RAW("    }\n")
19438
0
SLANG_RAW("};\n")
19439
0
SLANG_RAW("\n")
19440
0
SLANG_RAW("// 10.1.4 - Subobject Definitions\n")
19441
0
SLANG_RAW("\n")
19442
0
SLANG_RAW("// TODO: We may decide to support these, but their reliance on C++ implicit\n")
19443
0
SLANG_RAW("// constructor call syntax (`SomeType someVar(arg0, arg1);`) makes them\n")
19444
0
SLANG_RAW("// annoying for the current Slang parsing strategy, and using global variables\n")
19445
0
SLANG_RAW("// for this stuff comes across as a kludge rather than the best possible design.\n")
19446
0
SLANG_RAW("\n")
19447
0
SLANG_RAW("// 10.1.5 - Intersection Attributes Structure\n")
19448
0
SLANG_RAW("/// Built-in structure containing intersection attributes for triangle primitives.\n")
19449
0
SLANG_RAW("/// @category raytracing\n")
19450
0
SLANG_RAW("__target_intrinsic(hlsl, BuiltInTriangleIntersectionAttributes)\n")
19451
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, raytracing)]\n")
19452
0
SLANG_RAW("struct BuiltInTriangleIntersectionAttributes\n")
19453
0
SLANG_RAW("{\n")
19454
0
SLANG_RAW("    /// Barycentric coordinates of the intersection point on the triangle.\n")
19455
0
SLANG_RAW("    __target_intrinsic(hlsl, barycentrics)\n")
19456
0
SLANG_RAW("    float2 barycentrics;\n")
19457
0
SLANG_RAW("};\n")
19458
0
SLANG_RAW("\n")
19459
0
SLANG_RAW("// 10.2 Shaders\n")
19460
0
SLANG_RAW("\n")
19461
0
SLANG_RAW("// Right now new shader stages need to be added directly to the compiler\n")
19462
0
SLANG_RAW("// implementation, rather than being something that can be declared in the core module.\n")
19463
0
SLANG_RAW("\n")
19464
0
SLANG_RAW("// 10.3 - Intrinsics\n")
19465
0
SLANG_RAW("\n")
19466
0
SLANG_RAW("// 10.3.1\n")
19467
0
SLANG_RAW("\n")
19468
0
SLANG_RAW("// `executeCallableNV` is the GLSL intrinsic that will be used to implement\n")
19469
0
SLANG_RAW("// `CallShader()` for GLSL-based targets.\n")
19470
0
SLANG_RAW("//\n")
19471
0
SLANG_RAW("[require(glsl, raytracing_raygen_closesthit_miss_callable)]\n")
19472
0
SLANG_RAW("void __executeCallable(uint shaderIndex, int payloadLocation)\n")
19473
0
SLANG_RAW("{\n")
19474
0
SLANG_RAW("    __target_switch\n")
19475
0
SLANG_RAW("    {\n")
19476
0
SLANG_RAW("    case glsl: __intrinsic_asm \"executeCallableEXT\";\n")
19477
0
SLANG_RAW("    }\n")
19478
0
SLANG_RAW("}\n")
19479
0
SLANG_RAW("\n")
19480
0
SLANG_RAW("// Next is the custom intrinsic that will compute the payload location\n")
19481
0
SLANG_RAW("// for a type being used in a `CallShader()` call for GLSL-based targets.\n")
19482
0
SLANG_RAW("//\n")
19483
0
SLANG_RAW("__generic<Payload>\n")
19484
0
SLANG_RAW("[__readNone]\n")
19485
0
SLANG_RAW("__intrinsic_op(")
19486
0
SLANG_SPLICE(kIROp_GetVulkanRayTracingPayloadLocation
19487
0
)
19488
0
SLANG_RAW(")\n")
19489
0
SLANG_RAW("int __callablePayloadLocation(__ref Payload payload);\n")
19490
0
SLANG_RAW("\n")
19491
0
SLANG_RAW("// Now we provide a hard-coded definition of `CallShader()` for GLSL-based\n")
19492
0
SLANG_RAW("// targets, which maps the generic HLSL operation into the non-generic\n")
19493
0
SLANG_RAW("// GLSL equivalent.\n")
19494
0
SLANG_RAW("//\n")
19495
0
SLANG_RAW("/// Executes a callable shader with the specified payload.\n")
19496
0
SLANG_RAW("/// @param shaderIndex Index of the callable shader to execute\n")
19497
0
SLANG_RAW("/// @param payload Data structure to pass to and receive from the callable shader\n")
19498
0
SLANG_RAW("/// @remarks Used to implement dynamic shader calls during ray tracing\n")
19499
0
SLANG_RAW("/// @category raytracing\n")
19500
0
SLANG_RAW("__generic<Payload>\n")
19501
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_raygen_closesthit_miss_callable)]\n")
19502
0
SLANG_RAW("void CallShader(uint shaderIndex, inout Payload payload)\n")
19503
0
SLANG_RAW("{\n")
19504
0
SLANG_RAW("    __target_switch\n")
19505
0
SLANG_RAW("    {\n")
19506
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"CallShader\";\n")
19507
0
SLANG_RAW("    case glsl:\n")
19508
0
SLANG_RAW("        {\n")
19509
0
SLANG_RAW("            [__vulkanCallablePayload]\n")
19510
0
SLANG_RAW("            static Payload p;\n")
19511
0
SLANG_RAW("\n")
19512
0
SLANG_RAW("            p = payload;\n")
19513
0
SLANG_RAW("            __executeCallable(shaderIndex, __callablePayloadLocation(p));\n")
19514
0
SLANG_RAW("            payload = p;\n")
19515
0
SLANG_RAW("        }\n")
19516
0
SLANG_RAW("    case spirv:\n")
19517
0
SLANG_RAW("        {\n")
19518
0
SLANG_RAW("            [__vulkanCallablePayload]\n")
19519
0
SLANG_RAW("            static Payload p;\n")
19520
0
SLANG_RAW("\n")
19521
0
SLANG_RAW("            p = payload;\n")
19522
0
SLANG_RAW("            spirv_asm\n")
19523
0
SLANG_RAW("            {\n")
19524
0
SLANG_RAW("                OpExecuteCallableKHR $shaderIndex &p\n")
19525
0
SLANG_RAW("            };\n")
19526
0
SLANG_RAW("            payload = p;\n")
19527
0
SLANG_RAW("        }\n")
19528
0
SLANG_RAW("    }\n")
19529
0
SLANG_RAW("}\n")
19530
0
SLANG_RAW("\n")
19531
0
SLANG_RAW("// 10.3.2\n")
19532
0
SLANG_RAW("\n")
19533
0
SLANG_RAW("// Some functions only accept a \"struct type\" parameter. The\n")
19534
0
SLANG_RAW("// following function addresses this issue by transforming non-struct\n")
19535
0
SLANG_RAW("// parameters into a struct.\n")
19536
0
SLANG_RAW("// side effect typed use locations (`inout`,`out`, etc.) are managed.\n")
19537
0
SLANG_RAW("__generic<T>\n")
19538
0
SLANG_RAW("__intrinsic_op(")
19539
0
SLANG_SPLICE(kIROp_ForceVarIntoStructTemporarily
19540
0
)
19541
0
SLANG_RAW(")\n")
19542
0
SLANG_RAW("Ref<T> __forceVarIntoStructTemporarily(inout T maybeStruct);\n")
19543
0
SLANG_RAW("\n")
19544
0
SLANG_RAW("// Some functions require a struct type which is decorated with a [raypayload]\n")
19545
0
SLANG_RAW("// attribute. This will do the same as __forceVarIntoStructTemporarily and also\n")
19546
0
SLANG_RAW("// ensure that the struct type in question is decorated appropriately.\n")
19547
0
SLANG_RAW("__generic<T>\n")
19548
0
SLANG_RAW("__intrinsic_op(")
19549
0
SLANG_SPLICE(kIROp_ForceVarIntoRayPayloadStructTemporarily
19550
0
)
19551
0
SLANG_RAW(")\n")
19552
0
SLANG_RAW("Ref<T> __forceVarIntoRayPayloadStructTemporarily(inout T maybeStruct);\n")
19553
0
SLANG_RAW("\n")
19554
0
SLANG_RAW("__generic<payload_t>\n")
19555
0
SLANG_RAW("[require(hlsl, raytracing)]\n")
19556
0
SLANG_RAW("void __traceRayHLSL(\n")
19557
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
19558
0
SLANG_RAW("        uint RayFlags,\n")
19559
0
SLANG_RAW("        uint InstanceInclusionMask,\n")
19560
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
19561
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
19562
0
SLANG_RAW("        uint MissShaderIndex,\n")
19563
0
SLANG_RAW("        RayDesc Ray,\n")
19564
0
SLANG_RAW("        inout payload_t Payload)\n")
19565
0
SLANG_RAW("{\n")
19566
0
SLANG_RAW("    __target_switch\n")
19567
0
SLANG_RAW("    {\n")
19568
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"TraceRay\";\n")
19569
0
SLANG_RAW("    }\n")
19570
0
SLANG_RAW("}\n")
19571
0
SLANG_RAW("\n")
19572
0
SLANG_RAW("[require(glsl, raytracing_raygen_closesthit_miss)]\n")
19573
0
SLANG_RAW("void __traceRay(\n")
19574
0
SLANG_RAW("    RaytracingAccelerationStructure AccelerationStructure,\n")
19575
0
SLANG_RAW("    uint                            RayFlags,\n")
19576
0
SLANG_RAW("    uint                            InstanceInclusionMask,\n")
19577
0
SLANG_RAW("    uint                            RayContributionToHitGroupIndex,\n")
19578
0
SLANG_RAW("    uint                            MultiplierForGeometryContributionToHitGroupIndex,\n")
19579
0
SLANG_RAW("    uint                            MissShaderIndex,\n")
19580
0
SLANG_RAW("    float3                          Origin,\n")
19581
0
SLANG_RAW("    float                           TMin,\n")
19582
0
SLANG_RAW("    float3                          Direction,\n")
19583
0
SLANG_RAW("    float                           TMax,\n")
19584
0
SLANG_RAW("    int                             PayloadLocation)\n")
19585
0
SLANG_RAW("{\n")
19586
0
SLANG_RAW("    __target_switch\n")
19587
0
SLANG_RAW("    {\n")
19588
0
SLANG_RAW("    case glsl: __intrinsic_asm \"traceRayEXT\";\n")
19589
0
SLANG_RAW("    }\n")
19590
0
SLANG_RAW("}\n")
19591
0
SLANG_RAW("\n")
19592
0
SLANG_RAW("// TODO: Slang's parsing logic currently puts modifiers on\n")
19593
0
SLANG_RAW("// the `GenericDecl` rather than the inner decl when\n")
19594
0
SLANG_RAW("// using our default syntax, which seems wrong. We need\n")
19595
0
SLANG_RAW("// to fix this, but for now using the expanded `__generic`\n")
19596
0
SLANG_RAW("// syntax works in a pinch.\n")
19597
0
SLANG_RAW("//\n")
19598
0
SLANG_RAW("__generic<Payload>\n")
19599
0
SLANG_RAW("[__readNone]\n")
19600
0
SLANG_RAW("__intrinsic_op(")
19601
0
SLANG_SPLICE(kIROp_GetVulkanRayTracingPayloadLocation
19602
0
)
19603
0
SLANG_RAW(")\n")
19604
0
SLANG_RAW("int __rayPayloadLocation(__ref Payload payload);\n")
19605
0
SLANG_RAW("\n")
19606
0
SLANG_RAW("/// Traces a ray through the acceleration structure.\n")
19607
0
SLANG_RAW("/// @param AccelerationStructure The acceleration structure to traverse\n")
19608
0
SLANG_RAW("/// @param RayFlags Flags controlling ray behavior\n")
19609
0
SLANG_RAW("/// @param InstanceInclusionMask Mask for filtering instance visibility\n")
19610
0
SLANG_RAW("/// @param RayContributionToHitGroupIndex Offset for hit group indexing\n")
19611
0
SLANG_RAW("/// @param MultiplierForGeometryContributionToHitGroupIndex Multiplier for geometry-based hit group indexing\n")
19612
0
SLANG_RAW("/// @param MissShaderIndex Index of the miss shader to execute if no hit is found\n")
19613
0
SLANG_RAW("/// @param Ray Description of the ray to trace\n")
19614
0
SLANG_RAW("/// @param Payload Structure for passing data between shaders\n")
19615
0
SLANG_RAW("/// @remarks Core ray tracing function for initiating traversal\n")
19616
0
SLANG_RAW("/// @category raytracing\n")
19617
0
SLANG_RAW("[ForceInline]\n")
19618
0
SLANG_RAW("__generic<payload_t>\n")
19619
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_raygen_closesthit_miss)]\n")
19620
0
SLANG_RAW("void TraceRay(\n")
19621
0
SLANG_RAW("    RaytracingAccelerationStructure AccelerationStructure,\n")
19622
0
SLANG_RAW("    uint                            RayFlags,\n")
19623
0
SLANG_RAW("    uint                            InstanceInclusionMask,\n")
19624
0
SLANG_RAW("    uint                            RayContributionToHitGroupIndex,\n")
19625
0
SLANG_RAW("    uint                            MultiplierForGeometryContributionToHitGroupIndex,\n")
19626
0
SLANG_RAW("    uint                            MissShaderIndex,\n")
19627
0
SLANG_RAW("    RayDesc                         Ray,\n")
19628
0
SLANG_RAW("    inout payload_t                 Payload)\n")
19629
0
SLANG_RAW("{\n")
19630
0
SLANG_RAW("    __target_switch\n")
19631
0
SLANG_RAW("    {\n")
19632
0
SLANG_RAW("    case hlsl:\n")
19633
0
SLANG_RAW("        __traceRayHLSL(\n")
19634
0
SLANG_RAW("            AccelerationStructure,\n")
19635
0
SLANG_RAW("            RayFlags,\n")
19636
0
SLANG_RAW("            InstanceInclusionMask,\n")
19637
0
SLANG_RAW("            RayContributionToHitGroupIndex,\n")
19638
0
SLANG_RAW("            MultiplierForGeometryContributionToHitGroupIndex,\n")
19639
0
SLANG_RAW("            MissShaderIndex,\n")
19640
0
SLANG_RAW("            Ray,\n")
19641
0
SLANG_RAW("            __forceVarIntoRayPayloadStructTemporarily(Payload));\n")
19642
0
SLANG_RAW("        return;\n")
19643
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixTrace\";\n")
19644
0
SLANG_RAW("    case glsl:\n")
19645
0
SLANG_RAW("    {\n")
19646
0
SLANG_RAW("        [__vulkanRayPayload]\n")
19647
0
SLANG_RAW("        static payload_t p;\n")
19648
0
SLANG_RAW("\n")
19649
0
SLANG_RAW("        p = Payload;\n")
19650
0
SLANG_RAW("        __traceRay(\n")
19651
0
SLANG_RAW("            AccelerationStructure,\n")
19652
0
SLANG_RAW("            RayFlags,\n")
19653
0
SLANG_RAW("            InstanceInclusionMask,\n")
19654
0
SLANG_RAW("            RayContributionToHitGroupIndex,\n")
19655
0
SLANG_RAW("            MultiplierForGeometryContributionToHitGroupIndex,\n")
19656
0
SLANG_RAW("            MissShaderIndex,\n")
19657
0
SLANG_RAW("            Ray.Origin,\n")
19658
0
SLANG_RAW("            Ray.TMin,\n")
19659
0
SLANG_RAW("            Ray.Direction,\n")
19660
0
SLANG_RAW("            Ray.TMax,\n")
19661
0
SLANG_RAW("            __rayPayloadLocation(p));\n")
19662
0
SLANG_RAW("        Payload = p;\n")
19663
0
SLANG_RAW("    }\n")
19664
0
SLANG_RAW("    case spirv:\n")
19665
0
SLANG_RAW("    {\n")
19666
0
SLANG_RAW("        [__vulkanRayPayload]\n")
19667
0
SLANG_RAW("        static payload_t p;\n")
19668
0
SLANG_RAW("\n")
19669
0
SLANG_RAW("        p = Payload;\n")
19670
0
SLANG_RAW("        let origin = Ray.Origin;\n")
19671
0
SLANG_RAW("        let direction = Ray.Direction;\n")
19672
0
SLANG_RAW("        let tmin = Ray.TMin;\n")
19673
0
SLANG_RAW("        let tmax = Ray.TMax;\n")
19674
0
SLANG_RAW("        spirv_asm\n")
19675
0
SLANG_RAW("        {\n")
19676
0
SLANG_RAW("            OpTraceRayKHR\n")
19677
0
SLANG_RAW("                /**/ $AccelerationStructure\n")
19678
0
SLANG_RAW("                /**/ $RayFlags\n")
19679
0
SLANG_RAW("                /**/ $InstanceInclusionMask\n")
19680
0
SLANG_RAW("                /**/ $RayContributionToHitGroupIndex\n")
19681
0
SLANG_RAW("                /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
19682
0
SLANG_RAW("                /**/ $MissShaderIndex\n")
19683
0
SLANG_RAW("                /**/ $origin\n")
19684
0
SLANG_RAW("                /**/ $tmin\n")
19685
0
SLANG_RAW("                /**/ $direction\n")
19686
0
SLANG_RAW("                /**/ $tmax\n")
19687
0
SLANG_RAW("                /**/ &p;\n")
19688
0
SLANG_RAW("        };\n")
19689
0
SLANG_RAW("        Payload = p;\n")
19690
0
SLANG_RAW("    }\n")
19691
0
SLANG_RAW("    }\n")
19692
0
SLANG_RAW("}\n")
19693
0
SLANG_RAW("\n")
19694
0
SLANG_RAW("// NOTE!\n")
19695
0
SLANG_RAW("// The name of the following functions may change when DXR supports\n")
19696
0
SLANG_RAW("// a feature similar to the `GL_NV_ray_tracing_motion_blur` extension\n")
19697
0
SLANG_RAW("//\n")
19698
0
SLANG_RAW("// https://github.com/KhronosGroup/GLSL/blob/master/extensions/nv/GLSL_NV_ray_tracing_motion_blur.txt\n")
19699
0
SLANG_RAW("\n")
19700
0
SLANG_RAW("__generic<payload_t>\n")
19701
0
SLANG_RAW("[require(hlsl, raytracing_motionblur)]\n")
19702
0
SLANG_RAW("void __traceMotionRayHLSL(\n")
19703
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
19704
0
SLANG_RAW("        uint RayFlags,\n")
19705
0
SLANG_RAW("        uint InstanceInclusionMask,\n")
19706
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
19707
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
19708
0
SLANG_RAW("        uint MissShaderIndex,\n")
19709
0
SLANG_RAW("        RayDesc Ray,\n")
19710
0
SLANG_RAW("        float CurrentTime,\n")
19711
0
SLANG_RAW("        inout payload_t Payload)\n")
19712
0
SLANG_RAW("{\n")
19713
0
SLANG_RAW("    __target_switch\n")
19714
0
SLANG_RAW("    {\n")
19715
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"TraceMotionRay\";\n")
19716
0
SLANG_RAW("    }\n")
19717
0
SLANG_RAW("}\n")
19718
0
SLANG_RAW("\n")
19719
0
SLANG_RAW("__glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
19720
0
SLANG_RAW("[require(glsl, raytracing_motionblur_raygen_closesthit_miss)]\n")
19721
0
SLANG_RAW("void __traceMotionRay(\n")
19722
0
SLANG_RAW("    RaytracingAccelerationStructure AccelerationStructure,\n")
19723
0
SLANG_RAW("    uint                            RayFlags,\n")
19724
0
SLANG_RAW("    uint                            InstanceInclusionMask,\n")
19725
0
SLANG_RAW("    uint                            RayContributionToHitGroupIndex,\n")
19726
0
SLANG_RAW("    uint                            MultiplierForGeometryContributionToHitGroupIndex,\n")
19727
0
SLANG_RAW("    uint                            MissShaderIndex,\n")
19728
0
SLANG_RAW("    float3                          Origin,\n")
19729
0
SLANG_RAW("    float                           TMin,\n")
19730
0
SLANG_RAW("    float3                          Direction,\n")
19731
0
SLANG_RAW("    float                           TMax,\n")
19732
0
SLANG_RAW("    float                           CurrentTime,\n")
19733
0
SLANG_RAW("    int                             PayloadLocation)\n")
19734
0
SLANG_RAW("{\n")
19735
0
SLANG_RAW("    __target_switch\n")
19736
0
SLANG_RAW("    {\n")
19737
0
SLANG_RAW("    case glsl: __intrinsic_asm \"traceRayMotionNV\";\n")
19738
0
SLANG_RAW("    }\n")
19739
0
SLANG_RAW("}\n")
19740
0
SLANG_RAW("\n")
19741
0
SLANG_RAW("/// Traces a ray with motion blur support through the acceleration structure.\n")
19742
0
SLANG_RAW("/// @param AccelerationStructure The acceleration structure to traverse\n")
19743
0
SLANG_RAW("/// @param RayFlags Flags controlling ray behavior\n")
19744
0
SLANG_RAW("/// @param InstanceInclusionMask Mask for filtering instance visibility\n")
19745
0
SLANG_RAW("/// @param RayContributionToHitGroupIndex Offset for hit group indexing\n")
19746
0
SLANG_RAW("/// @param MultiplierForGeometryContributionToHitGroupIndex Multiplier for geometry-based hit group indexing\n")
19747
0
SLANG_RAW("/// @param MissShaderIndex Index of the miss shader to execute if no hit is found\n")
19748
0
SLANG_RAW("/// @param Ray Description of the ray to trace\n")
19749
0
SLANG_RAW("/// @param CurrentTime Time value for motion blur interpolation\n")
19750
0
SLANG_RAW("/// @param Payload Structure for passing data between shaders\n")
19751
0
SLANG_RAW("/// @remarks Extended version of TraceRay with motion blur support\n")
19752
0
SLANG_RAW("/// @category raytracing\n")
19753
0
SLANG_RAW("[ForceInline]\n")
19754
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_motionblur_raygen_closesthit_miss)]\n")
19755
0
SLANG_RAW("__generic<payload_t>\n")
19756
0
SLANG_RAW("void TraceMotionRay(\n")
19757
0
SLANG_RAW("    RaytracingAccelerationStructure AccelerationStructure,\n")
19758
0
SLANG_RAW("    uint                            RayFlags,\n")
19759
0
SLANG_RAW("    uint                            InstanceInclusionMask,\n")
19760
0
SLANG_RAW("    uint                            RayContributionToHitGroupIndex,\n")
19761
0
SLANG_RAW("    uint                            MultiplierForGeometryContributionToHitGroupIndex,\n")
19762
0
SLANG_RAW("    uint                            MissShaderIndex,\n")
19763
0
SLANG_RAW("    RayDesc                         Ray,\n")
19764
0
SLANG_RAW("    float                           CurrentTime,\n")
19765
0
SLANG_RAW("    inout payload_t                 Payload)\n")
19766
0
SLANG_RAW("{\n")
19767
0
SLANG_RAW("    __target_switch\n")
19768
0
SLANG_RAW("    {\n")
19769
0
SLANG_RAW("    case hlsl:\n")
19770
0
SLANG_RAW("        __traceMotionRayHLSL(\n")
19771
0
SLANG_RAW("            AccelerationStructure,\n")
19772
0
SLANG_RAW("            RayFlags,\n")
19773
0
SLANG_RAW("            InstanceInclusionMask,\n")
19774
0
SLANG_RAW("            RayContributionToHitGroupIndex,\n")
19775
0
SLANG_RAW("            MultiplierForGeometryContributionToHitGroupIndex,\n")
19776
0
SLANG_RAW("            MissShaderIndex,\n")
19777
0
SLANG_RAW("            Ray,\n")
19778
0
SLANG_RAW("            CurrentTime,\n")
19779
0
SLANG_RAW("            __forceVarIntoRayPayloadStructTemporarily(Payload));\n")
19780
0
SLANG_RAW("        return;\n")
19781
0
SLANG_RAW("    case glsl:\n")
19782
0
SLANG_RAW("    {\n")
19783
0
SLANG_RAW("        [__vulkanRayPayload]\n")
19784
0
SLANG_RAW("        static payload_t p;\n")
19785
0
SLANG_RAW("\n")
19786
0
SLANG_RAW("        p = Payload;\n")
19787
0
SLANG_RAW("        __traceMotionRay(\n")
19788
0
SLANG_RAW("            AccelerationStructure,\n")
19789
0
SLANG_RAW("            RayFlags,\n")
19790
0
SLANG_RAW("            InstanceInclusionMask,\n")
19791
0
SLANG_RAW("            RayContributionToHitGroupIndex,\n")
19792
0
SLANG_RAW("            MultiplierForGeometryContributionToHitGroupIndex,\n")
19793
0
SLANG_RAW("            MissShaderIndex,\n")
19794
0
SLANG_RAW("            Ray.Origin,\n")
19795
0
SLANG_RAW("            Ray.TMin,\n")
19796
0
SLANG_RAW("            Ray.Direction,\n")
19797
0
SLANG_RAW("            Ray.TMax,\n")
19798
0
SLANG_RAW("            CurrentTime,\n")
19799
0
SLANG_RAW("            __rayPayloadLocation(p));\n")
19800
0
SLANG_RAW("        Payload = p;\n")
19801
0
SLANG_RAW("    }\n")
19802
0
SLANG_RAW("    case spirv:\n")
19803
0
SLANG_RAW("    {\n")
19804
0
SLANG_RAW("        [__vulkanRayPayload]\n")
19805
0
SLANG_RAW("        static payload_t p;\n")
19806
0
SLANG_RAW("\n")
19807
0
SLANG_RAW("        let origin = Ray.Origin;\n")
19808
0
SLANG_RAW("        let direction = Ray.Direction;\n")
19809
0
SLANG_RAW("        let tmin = Ray.TMin;\n")
19810
0
SLANG_RAW("        let tmax = Ray.TMax;\n")
19811
0
SLANG_RAW("\n")
19812
0
SLANG_RAW("        p = Payload;\n")
19813
0
SLANG_RAW("        spirv_asm\n")
19814
0
SLANG_RAW("        {\n")
19815
0
SLANG_RAW("            OpCapability RayTracingMotionBlurNV;\n")
19816
0
SLANG_RAW("            OpExtension \"SPV_NV_ray_tracing_motion_blur\";\n")
19817
0
SLANG_RAW("\n")
19818
0
SLANG_RAW("            OpTraceRayMotionNV\n")
19819
0
SLANG_RAW("                /**/ $AccelerationStructure\n")
19820
0
SLANG_RAW("                /**/ $RayFlags\n")
19821
0
SLANG_RAW("                /**/ $InstanceInclusionMask\n")
19822
0
SLANG_RAW("                /**/ $RayContributionToHitGroupIndex\n")
19823
0
SLANG_RAW("                /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
19824
0
SLANG_RAW("                /**/ $MissShaderIndex\n")
19825
0
SLANG_RAW("                /**/ $origin\n")
19826
0
SLANG_RAW("                /**/ $tmin\n")
19827
0
SLANG_RAW("                /**/ $direction\n")
19828
0
SLANG_RAW("                /**/ $tmax\n")
19829
0
SLANG_RAW("                /**/ $CurrentTime\n")
19830
0
SLANG_RAW("                /**/ &p;\n")
19831
0
SLANG_RAW("        };\n")
19832
0
SLANG_RAW("        Payload = p;\n")
19833
0
SLANG_RAW("    }\n")
19834
0
SLANG_RAW("    }\n")
19835
0
SLANG_RAW("}\n")
19836
0
SLANG_RAW("\n")
19837
0
SLANG_RAW("// 10.3.3\n")
19838
0
SLANG_RAW("\n")
19839
0
SLANG_RAW("[require(glsl_spirv, raytracing_intersection)]\n")
19840
0
SLANG_RAW("bool __reportIntersection(float tHit, uint hitKind)\n")
19841
0
SLANG_RAW("{\n")
19842
0
SLANG_RAW("    __target_switch\n")
19843
0
SLANG_RAW("    {\n")
19844
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reportIntersectionEXT\";\n")
19845
0
SLANG_RAW("    case spirv:\n")
19846
0
SLANG_RAW("        return spirv_asm\n")
19847
0
SLANG_RAW("        {\n")
19848
0
SLANG_RAW("            result:$$bool = OpReportIntersectionKHR $tHit $hitKind;\n")
19849
0
SLANG_RAW("        };\n")
19850
0
SLANG_RAW("    }\n")
19851
0
SLANG_RAW("}\n")
19852
0
SLANG_RAW("\n")
19853
0
SLANG_RAW("/// Reports a hit from an intersection shader.\n")
19854
0
SLANG_RAW("/// @param tHit Distance along the ray where the intersection occurred\n")
19855
0
SLANG_RAW("/// @param hitKind User-defined value identifying the type of hit\n")
19856
0
SLANG_RAW("/// @param attributes Custom attributes for the intersection\n")
19857
0
SLANG_RAW("/// @return true if the hit was accepted, false if rejected\n")
19858
0
SLANG_RAW("/// @remarks Used in custom intersection shaders to report primitive intersections\n")
19859
0
SLANG_RAW("/// @category raytracing\n")
19860
0
SLANG_RAW("__generic<A>\n")
19861
0
SLANG_RAW("[ForceInline]\n")
19862
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_intersection)]\n")
19863
0
SLANG_RAW("bool ReportHit(float tHit, uint hitKind, A attributes)\n")
19864
0
SLANG_RAW("{\n")
19865
0
SLANG_RAW("    __target_switch\n")
19866
0
SLANG_RAW("    {\n")
19867
0
SLANG_RAW("    case hlsl:\n")
19868
0
SLANG_RAW("        __intrinsic_asm \"ReportHit($0, $1, $2)\";\n")
19869
0
SLANG_RAW("    case glsl:\n")
19870
0
SLANG_RAW("    case spirv:\n")
19871
0
SLANG_RAW("        [__vulkanHitAttributes]\n")
19872
0
SLANG_RAW("        static A a;\n")
19873
0
SLANG_RAW("        a = attributes;\n")
19874
0
SLANG_RAW("        return __reportIntersection(tHit, hitKind);\n")
19875
0
SLANG_RAW("    }\n")
19876
0
SLANG_RAW("}\n")
19877
0
SLANG_RAW("\n")
19878
0
SLANG_RAW("/// Reports a hit optimized for OptiX.\n")
19879
0
SLANG_RAW("/// @param tHit Distance along the ray where the intersection occurred\n")
19880
0
SLANG_RAW("/// @param hitKind User-defined value identifying the type of hit\n")
19881
0
SLANG_RAW("/// @param attribs Attribute values for the intersection\n")
19882
0
SLANG_RAW("/// @return true if the hit was accepted, false if rejected\n")
19883
0
SLANG_RAW("/// @remarks OptiX-specific version of ReportHit with optimized attribute handling\n")
19884
0
SLANG_RAW("/// @category raytracing\n")
19885
0
SLANG_RAW("__generic<each T : __BuiltinIntegerType>\n")
19886
0
SLANG_RAW("[ForceInline]\n")
19887
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_intersection)]\n")
19888
0
SLANG_RAW("bool ReportHitOptix(float tHit, uint hitKind, expand each T attribs)\n")
19889
0
SLANG_RAW("{\n")
19890
0
SLANG_RAW("    __target_switch\n")
19891
0
SLANG_RAW("    {\n")
19892
0
SLANG_RAW("    case cuda:\n")
19893
0
SLANG_RAW("        __intrinsic_asm \"optixReportIntersection\";\n")
19894
0
SLANG_RAW("    default:\n")
19895
0
SLANG_RAW("        return ReportHit(tHit, hitKind, makeTuple(expand each attribs));\n")
19896
0
SLANG_RAW("    }\n")
19897
0
SLANG_RAW("}\n")
19898
0
SLANG_RAW("\n")
19899
0
SLANG_RAW("// 10.3.4\n")
19900
0
SLANG_RAW("/// Ignores the current intersection and continues traversal.\n")
19901
0
SLANG_RAW("/// @remarks Used in any-hit shaders to reject potential intersections\n")
19902
0
SLANG_RAW("/// @category raytracing\n")
19903
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit)]\n")
19904
0
SLANG_RAW("void IgnoreHit()\n")
19905
0
SLANG_RAW("{\n")
19906
0
SLANG_RAW("    __target_switch\n")
19907
0
SLANG_RAW("    {\n")
19908
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"IgnoreHit\";\n")
19909
0
SLANG_RAW("    case glsl: __intrinsic_asm \"ignoreIntersectionEXT;\";\n")
19910
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixIgnoreIntersection\";\n")
19911
0
SLANG_RAW("    case spirv:\n")
19912
0
SLANG_RAW("        spirv_asm\n")
19913
0
SLANG_RAW("        {\n")
19914
0
SLANG_RAW("            OpIgnoreIntersectionKHR; %_ = OpLabel\n")
19915
0
SLANG_RAW("        };\n")
19916
0
SLANG_RAW("    }\n")
19917
0
SLANG_RAW("}\n")
19918
0
SLANG_RAW("\n")
19919
0
SLANG_RAW("// 10.3.5\n")
19920
0
SLANG_RAW("/// Accepts the current intersection and terminates further traversal.\n")
19921
0
SLANG_RAW("/// @remarks Used in any-hit shaders to immediately accept an intersection\n")
19922
0
SLANG_RAW("/// @category raytracing\n")
19923
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit)]\n")
19924
0
SLANG_RAW("void AcceptHitAndEndSearch()\n")
19925
0
SLANG_RAW("{\n")
19926
0
SLANG_RAW("    __target_switch\n")
19927
0
SLANG_RAW("    {\n")
19928
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"AcceptHitAndEndSearch\";\n")
19929
0
SLANG_RAW("    case glsl: __intrinsic_asm \"terminateRayEXT;\";\n")
19930
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixTerminateRay\";\n")
19931
0
SLANG_RAW("    case spirv:\n")
19932
0
SLANG_RAW("        spirv_asm\n")
19933
0
SLANG_RAW("        {\n")
19934
0
SLANG_RAW("            OpTerminateRayKHR; %_ = OpLabel\n")
19935
0
SLANG_RAW("        };\n")
19936
0
SLANG_RAW("    }\n")
19937
0
SLANG_RAW("}\n")
19938
0
SLANG_RAW("\n")
19939
0
SLANG_RAW("// 10.4 - System Values and Special Semantics\n")
19940
0
SLANG_RAW("\n")
19941
0
SLANG_RAW("// TODO: Many of these functions need to be restricted so that\n")
19942
0
SLANG_RAW("// they can only be accessed from specific stages.\n")
19943
0
SLANG_RAW("\n")
19944
0
SLANG_RAW("// 10.4.1 - Ray Dispatch System Values\n")
19945
0
SLANG_RAW("\n")
19946
0
SLANG_RAW("/// Returns the current ray dispatch coordinates.\n")
19947
0
SLANG_RAW("/// @return 3D index of the current ray being processed\n")
19948
0
SLANG_RAW("/// @remarks Available in all ray tracing shader stages\n")
19949
0
SLANG_RAW("/// @category raytracing\n")
19950
0
SLANG_RAW("[NonUniformReturn]\n")
19951
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_allstages)]\n")
19952
0
SLANG_RAW("uint3 DispatchRaysIndex()\n")
19953
0
SLANG_RAW("{\n")
19954
0
SLANG_RAW("    __target_switch\n")
19955
0
SLANG_RAW("    {\n")
19956
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"DispatchRaysIndex\";\n")
19957
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_LaunchIDEXT)\";\n")
19958
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetLaunchIndex\";\n")
19959
0
SLANG_RAW("    case spirv:\n")
19960
0
SLANG_RAW("        return spirv_asm\n")
19961
0
SLANG_RAW("        {\n")
19962
0
SLANG_RAW("            result:$$uint3 = OpLoad builtin(LaunchIdKHR:uint3);\n")
19963
0
SLANG_RAW("        };\n")
19964
0
SLANG_RAW("    }\n")
19965
0
SLANG_RAW("}\n")
19966
0
SLANG_RAW("\n")
19967
0
SLANG_RAW("/// Returns the dimensions of the ray dispatch.\n")
19968
0
SLANG_RAW("/// @return 3D dimensions of the ray dispatch grid\n")
19969
0
SLANG_RAW("/// @remarks Available in all ray tracing shader stages\n")
19970
0
SLANG_RAW("/// @category raytracing\n")
19971
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_allstages)]\n")
19972
0
SLANG_RAW("uint3 DispatchRaysDimensions()\n")
19973
0
SLANG_RAW("{\n")
19974
0
SLANG_RAW("    __target_switch\n")
19975
0
SLANG_RAW("    {\n")
19976
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"DispatchRaysDimensions\";\n")
19977
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_LaunchSizeEXT)\";\n")
19978
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetLaunchDimensions\";\n")
19979
0
SLANG_RAW("    case spirv:\n")
19980
0
SLANG_RAW("        return spirv_asm\n")
19981
0
SLANG_RAW("        {\n")
19982
0
SLANG_RAW("            result:$$uint3 = OpLoad builtin(LaunchSizeKHR:uint3);\n")
19983
0
SLANG_RAW("        };\n")
19984
0
SLANG_RAW("    }\n")
19985
0
SLANG_RAW("}\n")
19986
0
SLANG_RAW("\n")
19987
0
SLANG_RAW("// 10.4.2 - Ray System Values\n")
19988
0
SLANG_RAW("\n")
19989
0
SLANG_RAW("/// Returns the origin of the current ray in world space.\n")
19990
0
SLANG_RAW("/// @return World-space position where the ray originated\n")
19991
0
SLANG_RAW("/// @remarks Available in any-hit, closest-hit, intersection, and miss shaders\n")
19992
0
SLANG_RAW("/// @category raytracing\n")
19993
0
SLANG_RAW("[NonUniformReturn]\n")
19994
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection_miss)]\n")
19995
0
SLANG_RAW("float3 WorldRayOrigin()\n")
19996
0
SLANG_RAW("{\n")
19997
0
SLANG_RAW("    __target_switch\n")
19998
0
SLANG_RAW("    {\n")
19999
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"WorldRayOrigin\";\n")
20000
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_WorldRayOriginEXT)\";\n")
20001
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetWorldRayOrigin\";\n")
20002
0
SLANG_RAW("    case spirv:\n")
20003
0
SLANG_RAW("        return spirv_asm\n")
20004
0
SLANG_RAW("        {\n")
20005
0
SLANG_RAW("            result:$$float3 = OpLoad builtin(WorldRayOriginKHR:float3);\n")
20006
0
SLANG_RAW("        };\n")
20007
0
SLANG_RAW("    }\n")
20008
0
SLANG_RAW("}\n")
20009
0
SLANG_RAW("\n")
20010
0
SLANG_RAW("/// Returns the direction of the current ray in world space.\n")
20011
0
SLANG_RAW("/// @return Normalized world-space direction vector of the ray\n")
20012
0
SLANG_RAW("/// @remarks Available in any-hit, closest-hit, intersection, and miss shaders\n")
20013
0
SLANG_RAW("/// @category raytracing\n")
20014
0
SLANG_RAW("[NonUniformReturn]\n")
20015
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection_miss)]\n")
20016
0
SLANG_RAW("float3 WorldRayDirection()\n")
20017
0
SLANG_RAW("{\n")
20018
0
SLANG_RAW("    __target_switch\n")
20019
0
SLANG_RAW("    {\n")
20020
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"WorldRayDirection\";\n")
20021
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_WorldRayDirectionEXT)\";\n")
20022
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetWorldRayDirection\";\n")
20023
0
SLANG_RAW("    case spirv:\n")
20024
0
SLANG_RAW("        return spirv_asm\n")
20025
0
SLANG_RAW("        {\n")
20026
0
SLANG_RAW("            result:$$float3 = OpLoad builtin(WorldRayDirectionKHR:float3);\n")
20027
0
SLANG_RAW("        };\n")
20028
0
SLANG_RAW("    }\n")
20029
0
SLANG_RAW("}\n")
20030
0
SLANG_RAW("\n")
20031
0
SLANG_RAW("/// Returns the minimum valid intersection distance for the current ray.\n")
20032
0
SLANG_RAW("/// @return Minimum distance along the ray where intersections are considered\n")
20033
0
SLANG_RAW("/// @remarks Used to prevent self-intersections and near-plane clipping\n")
20034
0
SLANG_RAW("/// @category raytracing\n")
20035
0
SLANG_RAW("[NonUniformReturn]\n")
20036
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection_miss)]\n")
20037
0
SLANG_RAW("float RayTMin()\n")
20038
0
SLANG_RAW("{\n")
20039
0
SLANG_RAW("    __target_switch\n")
20040
0
SLANG_RAW("    {\n")
20041
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"RayTMin\";\n")
20042
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_RayTminEXT)\";\n")
20043
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetRayTmin\";\n")
20044
0
SLANG_RAW("    case spirv:\n")
20045
0
SLANG_RAW("        return spirv_asm\n")
20046
0
SLANG_RAW("        {\n")
20047
0
SLANG_RAW("            result:$$float = OpLoad builtin(RayTminKHR:float);\n")
20048
0
SLANG_RAW("        };\n")
20049
0
SLANG_RAW("    }\n")
20050
0
SLANG_RAW("}\n")
20051
0
SLANG_RAW("\n")
20052
0
SLANG_RAW("// Note: The `RayTCurrent()` intrinsic should translate to\n")
20053
0
SLANG_RAW("// either `gl_HitTNV` (for hit shaders) or `gl_RayTmaxNV`\n")
20054
0
SLANG_RAW("// (for intersection shaders). Right now we are handling this\n")
20055
0
SLANG_RAW("// during code emission, for simplicity.\n")
20056
0
SLANG_RAW("//\n")
20057
0
SLANG_RAW("// TODO: Once the compiler supports a more refined concept\n")
20058
0
SLANG_RAW("// of profiles/capabilities and overloading based on them,\n")
20059
0
SLANG_RAW("// we should simply provide two overloads here, specialized\n")
20060
0
SLANG_RAW("// to the appropriate Vulkan stages.\n")
20061
0
SLANG_RAW("//\n")
20062
0
SLANG_RAW("\n")
20063
0
SLANG_RAW("/// Returns the current intersection distance or maximum ray distance.\n")
20064
0
SLANG_RAW("/// @return Current t-value for hit shaders or maximum distance for intersection shaders\n")
20065
0
SLANG_RAW("/// @remarks Interpretation depends on shader stage (hit vs. intersection)\n")
20066
0
SLANG_RAW("/// @category raytracing\n")
20067
0
SLANG_RAW("[NonUniformReturn]\n")
20068
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection_miss)]\n")
20069
0
SLANG_RAW("float RayTCurrent()\n")
20070
0
SLANG_RAW("{\n")
20071
0
SLANG_RAW("    __target_switch\n")
20072
0
SLANG_RAW("    {\n")
20073
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"RayTCurrent\";\n")
20074
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_RayTmaxEXT)\";\n")
20075
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetRayTmax\";\n")
20076
0
SLANG_RAW("    case spirv:\n")
20077
0
SLANG_RAW("        return spirv_asm\n")
20078
0
SLANG_RAW("        {\n")
20079
0
SLANG_RAW("            result:$$float = OpLoad builtin(RayTmaxKHR:float);\n")
20080
0
SLANG_RAW("        };\n")
20081
0
SLANG_RAW("    }\n")
20082
0
SLANG_RAW("}\n")
20083
0
SLANG_RAW("\n")
20084
0
SLANG_RAW("/// Returns the flags used when tracing the current ray.\n")
20085
0
SLANG_RAW("/// @return Combination of RAY_FLAG values used for this ray\n")
20086
0
SLANG_RAW("/// @remarks Allows shaders to modify behavior based on ray trace flags\n")
20087
0
SLANG_RAW("/// @category raytracing\n")
20088
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection_miss)]\n")
20089
0
SLANG_RAW("uint RayFlags()\n")
20090
0
SLANG_RAW("{\n")
20091
0
SLANG_RAW("    __target_switch\n")
20092
0
SLANG_RAW("    {\n")
20093
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"RayFlags\";\n")
20094
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_IncomingRayFlagsEXT)\";\n")
20095
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetRayFlags\";\n")
20096
0
SLANG_RAW("    case spirv:\n")
20097
0
SLANG_RAW("        return spirv_asm\n")
20098
0
SLANG_RAW("        {\n")
20099
0
SLANG_RAW("            result:$$uint = OpLoad builtin(IncomingRayFlagsKHR:uint);\n")
20100
0
SLANG_RAW("        };\n")
20101
0
SLANG_RAW("    }\n")
20102
0
SLANG_RAW("}\n")
20103
0
SLANG_RAW("\n")
20104
0
SLANG_RAW("// 10.4.3 - Primitive/Object Space System Values\n")
20105
0
SLANG_RAW("\n")
20106
0
SLANG_RAW("/// Returns the index of the current instance in the acceleration structure.\n")
20107
0
SLANG_RAW("/// @return Zero-based index of the current instance\n")
20108
0
SLANG_RAW("/// @remarks Available in any-hit, closest-hit, and intersection shaders\n")
20109
0
SLANG_RAW("/// @category raytracing\n")
20110
0
SLANG_RAW("[NonUniformReturn]\n")
20111
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20112
0
SLANG_RAW("uint InstanceIndex()\n")
20113
0
SLANG_RAW("{\n")
20114
0
SLANG_RAW("    __target_switch\n")
20115
0
SLANG_RAW("    {\n")
20116
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"InstanceIndex\";\n")
20117
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_InstanceID)\";\n")
20118
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetInstanceIndex\";\n")
20119
0
SLANG_RAW("    case spirv:\n")
20120
0
SLANG_RAW("        return spirv_asm\n")
20121
0
SLANG_RAW("        {\n")
20122
0
SLANG_RAW("            result:$$uint = OpLoad builtin(InstanceId:uint);\n")
20123
0
SLANG_RAW("        };\n")
20124
0
SLANG_RAW("    }\n")
20125
0
SLANG_RAW("}\n")
20126
0
SLANG_RAW("\n")
20127
0
SLANG_RAW("/// Returns the user-provided ID of the current instance.\n")
20128
0
SLANG_RAW("/// @return Custom instance identifier set during acceleration structure build\n")
20129
0
SLANG_RAW("/// @remarks Used for instance-specific shader behavior\n")
20130
0
SLANG_RAW("/// @category raytracing\n")
20131
0
SLANG_RAW("[NonUniformReturn]\n")
20132
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20133
0
SLANG_RAW("uint InstanceID()\n")
20134
0
SLANG_RAW("{\n")
20135
0
SLANG_RAW("    __target_switch\n")
20136
0
SLANG_RAW("    {\n")
20137
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"InstanceID\";\n")
20138
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_InstanceCustomIndexEXT)\";\n")
20139
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetInstanceId\";\n")
20140
0
SLANG_RAW("    case spirv:\n")
20141
0
SLANG_RAW("        return spirv_asm\n")
20142
0
SLANG_RAW("        {\n")
20143
0
SLANG_RAW("            result:$$uint = OpLoad builtin(InstanceCustomIndexKHR:uint);\n")
20144
0
SLANG_RAW("        };\n")
20145
0
SLANG_RAW("    }\n")
20146
0
SLANG_RAW("}\n")
20147
0
SLANG_RAW("\n")
20148
0
SLANG_RAW("/// Returns the index of the current primitive within its geometry.\n")
20149
0
SLANG_RAW("/// @return Zero-based index of the intersected primitive\n")
20150
0
SLANG_RAW("/// @remarks Available in any-hit, closest-hit, and intersection shaders\n")
20151
0
SLANG_RAW("/// @category raytracing\n")
20152
0
SLANG_RAW("[NonUniformReturn]\n")
20153
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20154
0
SLANG_RAW("uint PrimitiveIndex()\n")
20155
0
SLANG_RAW("{\n")
20156
0
SLANG_RAW("    __target_switch\n")
20157
0
SLANG_RAW("    {\n")
20158
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"PrimitiveIndex\";\n")
20159
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_PrimitiveID)\";\n")
20160
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetPrimitiveIndex\";\n")
20161
0
SLANG_RAW("    case spirv:\n")
20162
0
SLANG_RAW("        return spirv_asm\n")
20163
0
SLANG_RAW("        {\n")
20164
0
SLANG_RAW("            result:$$uint = OpLoad builtin(PrimitiveId:uint);\n")
20165
0
SLANG_RAW("        };\n")
20166
0
SLANG_RAW("    }\n")
20167
0
SLANG_RAW("}\n")
20168
0
SLANG_RAW("\n")
20169
0
SLANG_RAW("/// Returns the ray origin in object space of the current instance.\n")
20170
0
SLANG_RAW("/// @return Object-space position where the ray originated\n")
20171
0
SLANG_RAW("/// @remarks Transformed by the inverse of the instance transform\n")
20172
0
SLANG_RAW("/// @category raytracing\n")
20173
0
SLANG_RAW("[NonUniformReturn]\n")
20174
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20175
0
SLANG_RAW("float3 ObjectRayOrigin()\n")
20176
0
SLANG_RAW("{\n")
20177
0
SLANG_RAW("    __target_switch\n")
20178
0
SLANG_RAW("    {\n")
20179
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"ObjectRayOrigin\";\n")
20180
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_ObjectRayOriginEXT)\";\n")
20181
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetObjectRayOrigin\";\n")
20182
0
SLANG_RAW("    case spirv:\n")
20183
0
SLANG_RAW("        return spirv_asm\n")
20184
0
SLANG_RAW("        {\n")
20185
0
SLANG_RAW("            result:$$float3 = OpLoad builtin(ObjectRayOriginKHR:float3);\n")
20186
0
SLANG_RAW("        };\n")
20187
0
SLANG_RAW("    }\n")
20188
0
SLANG_RAW("}\n")
20189
0
SLANG_RAW("\n")
20190
0
SLANG_RAW("/// Returns the ray direction in object space of the current instance.\n")
20191
0
SLANG_RAW("/// @return Object-space direction vector of the ray\n")
20192
0
SLANG_RAW("/// @remarks Transformed by the inverse of the instance transform\n")
20193
0
SLANG_RAW("/// @category raytracing\n")
20194
0
SLANG_RAW("[NonUniformReturn]\n")
20195
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20196
0
SLANG_RAW("float3 ObjectRayDirection()\n")
20197
0
SLANG_RAW("{\n")
20198
0
SLANG_RAW("    __target_switch\n")
20199
0
SLANG_RAW("    {\n")
20200
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"ObjectRayDirection\";\n")
20201
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_ObjectRayDirectionEXT)\";\n")
20202
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetObjectRayDirection\";\n")
20203
0
SLANG_RAW("    case spirv:\n")
20204
0
SLANG_RAW("        return spirv_asm\n")
20205
0
SLANG_RAW("        {\n")
20206
0
SLANG_RAW("            result:$$float3 = OpLoad builtin(ObjectRayDirectionKHR:float3);\n")
20207
0
SLANG_RAW("        };\n")
20208
0
SLANG_RAW("    }\n")
20209
0
SLANG_RAW("}\n")
20210
0
SLANG_RAW("\n")
20211
0
SLANG_RAW("// TODO: optix has an optixGetObjectToWorldTransformMatrix function that returns 12\n")
20212
0
SLANG_RAW("// floats by reference.\n")
20213
0
SLANG_RAW("/// Returns the object-to-world transformation matrix (3x4).\n")
20214
0
SLANG_RAW("/// @return 3x4 matrix transforming from object to world space\n")
20215
0
SLANG_RAW("/// @remarks Includes position and orientation of the current instance\n")
20216
0
SLANG_RAW("/// @category raytracing\n")
20217
0
SLANG_RAW("[NonUniformReturn]\n")
20218
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20219
0
SLANG_RAW("float3x4 ObjectToWorld3x4()\n")
20220
0
SLANG_RAW("{\n")
20221
0
SLANG_RAW("    __target_switch\n")
20222
0
SLANG_RAW("    {\n")
20223
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"ObjectToWorld3x4\";\n")
20224
0
SLANG_RAW("    case glsl: __intrinsic_asm \"transpose(gl_ObjectToWorldEXT)\";\n")
20225
0
SLANG_RAW("    case spirv:\n")
20226
0
SLANG_RAW("        return spirv_asm\n")
20227
0
SLANG_RAW("        {\n")
20228
0
SLANG_RAW("            %mat:$$float4x3 = OpLoad builtin(ObjectToWorldKHR:float4x3);\n")
20229
0
SLANG_RAW("            result:$$float3x4 = OpTranspose %mat;\n")
20230
0
SLANG_RAW("        };\n")
20231
0
SLANG_RAW("    }\n")
20232
0
SLANG_RAW("}\n")
20233
0
SLANG_RAW("\n")
20234
0
SLANG_RAW("/// Returns the world-to-object transformation matrix (3x4).\n")
20235
0
SLANG_RAW("/// @return 3x4 matrix transforming from world to object space\n")
20236
0
SLANG_RAW("/// @remarks Inverse of the object-to-world transform\n")
20237
0
SLANG_RAW("/// @category raytracing\n")
20238
0
SLANG_RAW("[NonUniformReturn]\n")
20239
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20240
0
SLANG_RAW("float3x4 WorldToObject3x4()\n")
20241
0
SLANG_RAW("{\n")
20242
0
SLANG_RAW("    __target_switch\n")
20243
0
SLANG_RAW("    {\n")
20244
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"WorldToObject3x4\";\n")
20245
0
SLANG_RAW("    case glsl: __intrinsic_asm \"transpose(gl_WorldToObjectEXT)\";\n")
20246
0
SLANG_RAW("    case spirv:\n")
20247
0
SLANG_RAW("        return spirv_asm\n")
20248
0
SLANG_RAW("        {\n")
20249
0
SLANG_RAW("            %mat:$$float4x3 = OpLoad builtin(WorldToObjectKHR:float4x3);\n")
20250
0
SLANG_RAW("            result:$$float3x4 = OpTranspose %mat;\n")
20251
0
SLANG_RAW("        };\n")
20252
0
SLANG_RAW("    }\n")
20253
0
SLANG_RAW("}\n")
20254
0
SLANG_RAW("\n")
20255
0
SLANG_RAW("/// Returns the object-to-world transformation matrix (4x3).\n")
20256
0
SLANG_RAW("/// @return 4x3 matrix transforming from object to world space\n")
20257
0
SLANG_RAW("/// @remarks Transposed version of ObjectToWorld3x4\n")
20258
0
SLANG_RAW("/// @category raytracing\n")
20259
0
SLANG_RAW("[NonUniformReturn]\n")
20260
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20261
0
SLANG_RAW("float4x3 ObjectToWorld4x3()\n")
20262
0
SLANG_RAW("{\n")
20263
0
SLANG_RAW("    __target_switch\n")
20264
0
SLANG_RAW("    {\n")
20265
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"ObjectToWorld4x3\";\n")
20266
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_ObjectToWorldEXT)\";\n")
20267
0
SLANG_RAW("    case spirv:\n")
20268
0
SLANG_RAW("        return spirv_asm\n")
20269
0
SLANG_RAW("        {\n")
20270
0
SLANG_RAW("            result:$$float4x3 = OpLoad builtin(ObjectToWorldKHR:float4x3);\n")
20271
0
SLANG_RAW("        };\n")
20272
0
SLANG_RAW("    }\n")
20273
0
SLANG_RAW("}\n")
20274
0
SLANG_RAW("\n")
20275
0
SLANG_RAW("/// Returns the world-to-object transformation matrix (4x3).\n")
20276
0
SLANG_RAW("/// @return 4x3 matrix transforming from world to object space\n")
20277
0
SLANG_RAW("/// @remarks Transposed version of WorldToObject3x4\n")
20278
0
SLANG_RAW("/// @category raytracing\n")
20279
0
SLANG_RAW("[NonUniformReturn]\n")
20280
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20281
0
SLANG_RAW("float4x3 WorldToObject4x3()\n")
20282
0
SLANG_RAW("{\n")
20283
0
SLANG_RAW("    __target_switch\n")
20284
0
SLANG_RAW("    {\n")
20285
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"WorldToObject4x3\";\n")
20286
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_WorldToObjectEXT)\";\n")
20287
0
SLANG_RAW("    case spirv:\n")
20288
0
SLANG_RAW("        return spirv_asm\n")
20289
0
SLANG_RAW("        {\n")
20290
0
SLANG_RAW("            result:$$float4x3 = OpLoad builtin(WorldToObjectKHR:float4x3);\n")
20291
0
SLANG_RAW("        };\n")
20292
0
SLANG_RAW("    }\n")
20293
0
SLANG_RAW("}\n")
20294
0
SLANG_RAW("\n")
20295
0
SLANG_RAW("// NOTE!\n")
20296
0
SLANG_RAW("// The name of the following functions may change when DXR supports\n")
20297
0
SLANG_RAW("// a feature similar to the `GL_NV_ray_tracing_motion_blur` extension\n")
20298
0
SLANG_RAW("\n")
20299
0
SLANG_RAW("/// Returns the current time value for motion blur.\n")
20300
0
SLANG_RAW("/// @return Time value between 0 and 1 for motion blur interpolation\n")
20301
0
SLANG_RAW("/// @remarks Available when motion blur extension is enabled\n")
20302
0
SLANG_RAW("/// @category raytracing\n")
20303
0
SLANG_RAW("__glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
20304
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
20305
0
SLANG_RAW("[NonUniformReturn]\n")
20306
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_motionblur_anyhit_closesthit_intersection_miss)]\n")
20307
0
SLANG_RAW("float RayCurrentTime()\n")
20308
0
SLANG_RAW("{\n")
20309
0
SLANG_RAW("    __target_switch\n")
20310
0
SLANG_RAW("    {\n")
20311
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"RayCurrentTime\";\n")
20312
0
SLANG_RAW("    case glsl:  __intrinsic_asm \"(gl_CurrentRayTimeNV)\";\n")
20313
0
SLANG_RAW("    case spirv:\n")
20314
0
SLANG_RAW("        return spirv_asm\n")
20315
0
SLANG_RAW("        {\n")
20316
0
SLANG_RAW("            result:$$float = OpLoad builtin(CurrentRayTimeNV:float);\n")
20317
0
SLANG_RAW("        };\n")
20318
0
SLANG_RAW("    }\n")
20319
0
SLANG_RAW("}\n")
20320
0
SLANG_RAW("\n")
20321
0
SLANG_RAW("/// @category raytracing\n")
20322
0
SLANG_RAW("[__requiresNVAPI]\n")
20323
0
SLANG_RAW("__glsl_extension(GL_NV_cluster_acceleration_structure)\n")
20324
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
20325
0
SLANG_RAW("[NonUniformReturn]\n")
20326
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit)]\n")
20327
0
SLANG_RAW("int GetClusterID()\n")
20328
0
SLANG_RAW("{\n")
20329
0
SLANG_RAW("    __target_switch\n")
20330
0
SLANG_RAW("    {\n")
20331
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"NvRtGetClusterID\";\n")
20332
0
SLANG_RAW("    case glsl:  __intrinsic_asm \"(gl_ClusterIDNV)\";\n")
20333
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixGetClusterId\";\n")
20334
0
SLANG_RAW("    case spirv:\n")
20335
0
SLANG_RAW("        return spirv_asm\n")
20336
0
SLANG_RAW("        {\n")
20337
0
SLANG_RAW("            result:$$int = OpLoad builtin(ClusterIDNV:int);\n")
20338
0
SLANG_RAW("        };\n")
20339
0
SLANG_RAW("    }\n")
20340
0
SLANG_RAW("}\n")
20341
0
SLANG_RAW("\n")
20342
0
SLANG_RAW("/// @category raytracing\n")
20343
0
SLANG_RAW("[__requiresNVAPI]\n")
20344
0
SLANG_RAW("[NonUniformReturn]\n")
20345
0
SLANG_RAW("[require(cuda_hlsl_spirv, raytracing_lss)]\n")
20346
0
SLANG_RAW("float4 GetSpherePositionAndRadius()\n")
20347
0
SLANG_RAW("{\n")
20348
0
SLANG_RAW("    __target_switch\n")
20349
0
SLANG_RAW("    {\n")
20350
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvRtSphereObjectPositionAndRadius\";\n")
20351
0
SLANG_RAW("    case cuda:\n")
20352
0
SLANG_RAW("        {\n")
20353
0
SLANG_RAW("            __intrinsic_asm \"optixGetSpherePositionAndRadius\";\n")
20354
0
SLANG_RAW("        }\n")
20355
0
SLANG_RAW("    case spirv:\n")
20356
0
SLANG_RAW("        return spirv_asm\n")
20357
0
SLANG_RAW("        {\n")
20358
0
SLANG_RAW("            OpExtension \"SPV_NV_linear_swept_spheres\";\n")
20359
0
SLANG_RAW("            OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
20360
0
SLANG_RAW("            OpCapability RayTracingSpheresGeometryNV;\n")
20361
0
SLANG_RAW("            %pos:$$float3 = OpLoad builtin(HitSpherePositionNV:float3);\n")
20362
0
SLANG_RAW("            %rad:$$float = OpLoad builtin(HitSphereRadiusNV:float);\n")
20363
0
SLANG_RAW("            result:$$float4 = OpCompositeConstruct %pos %rad;\n")
20364
0
SLANG_RAW("        };\n")
20365
0
SLANG_RAW("    }\n")
20366
0
SLANG_RAW("}\n")
20367
0
SLANG_RAW("\n")
20368
0
SLANG_RAW("/// @category raytracing\n")
20369
0
SLANG_RAW("[__requiresNVAPI]\n")
20370
0
SLANG_RAW("[NonUniformReturn]\n")
20371
0
SLANG_RAW("[require(cuda_hlsl_spirv, raytracing_lss)]\n")
20372
0
SLANG_RAW("float2x4 GetLssPositionsAndRadii()\n")
20373
0
SLANG_RAW("{\n")
20374
0
SLANG_RAW("    __target_switch\n")
20375
0
SLANG_RAW("    {\n")
20376
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvRtLssObjectPositionsAndRadii\";\n")
20377
0
SLANG_RAW("    case cuda:\n")
20378
0
SLANG_RAW("        {\n")
20379
0
SLANG_RAW("            __intrinsic_asm \"optixGetLssPositionsAndRadii\";\n")
20380
0
SLANG_RAW("        }\n")
20381
0
SLANG_RAW("    case spirv:\n")
20382
0
SLANG_RAW("        return spirv_asm\n")
20383
0
SLANG_RAW("        {\n")
20384
0
SLANG_RAW("            OpExtension \"SPV_NV_linear_swept_spheres\";\n")
20385
0
SLANG_RAW("            OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
20386
0
SLANG_RAW("            OpCapability RayTracingSpheresGeometryNV;\n")
20387
0
SLANG_RAW("            %positions:$$float3[2] = OpLoad builtin(HitLSSPositionsNV:float3[2]);\n")
20388
0
SLANG_RAW("            %radii:$$float[2] = OpLoad builtin(HitLSSRadiiNV:float[2]);\n")
20389
0
SLANG_RAW("            %r0:$$float = OpCompositeExtract %radii 0;\n")
20390
0
SLANG_RAW("            %r1:$$float = OpCompositeExtract %radii 1;\n")
20391
0
SLANG_RAW("            %p0:$$float3 = OpCompositeExtract %positions 0;\n")
20392
0
SLANG_RAW("            %p1:$$float3 = OpCompositeExtract %positions 1;\n")
20393
0
SLANG_RAW("            %a:$$float4 = OpCompositeConstruct %p0 %r0;\n")
20394
0
SLANG_RAW("            %b:$$float4 = OpCompositeConstruct %p1 %r1;\n")
20395
0
SLANG_RAW("            result:$$float2x4 = OpCompositeConstruct %a %b;\n")
20396
0
SLANG_RAW("        };\n")
20397
0
SLANG_RAW("\n")
20398
0
SLANG_RAW("    }\n")
20399
0
SLANG_RAW("}\n")
20400
0
SLANG_RAW("\n")
20401
0
SLANG_RAW("/// @category raytracing\n")
20402
0
SLANG_RAW("[__requiresNVAPI]\n")
20403
0
SLANG_RAW("[NonUniformReturn]\n")
20404
0
SLANG_RAW("[require(cuda_hlsl_spirv, raytracing_lss)]\n")
20405
0
SLANG_RAW("bool IsSphereHit()\n")
20406
0
SLANG_RAW("{\n")
20407
0
SLANG_RAW("    __target_switch\n")
20408
0
SLANG_RAW("    {\n")
20409
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvRtIsSphereHit\";\n")
20410
0
SLANG_RAW("    case cuda:\n")
20411
0
SLANG_RAW("        {\n")
20412
0
SLANG_RAW("            __intrinsic_asm \"optixIsSphereHit\";\n")
20413
0
SLANG_RAW("        }\n")
20414
0
SLANG_RAW("    case spirv:\n")
20415
0
SLANG_RAW("        return spirv_asm\n")
20416
0
SLANG_RAW("        {\n")
20417
0
SLANG_RAW("            OpExtension \"SPV_NV_linear_swept_spheres\";\n")
20418
0
SLANG_RAW("            OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
20419
0
SLANG_RAW("            OpCapability RayTracingSpheresGeometryNV;\n")
20420
0
SLANG_RAW("            result:$$bool = OpLoad builtin(HitIsSphereNV:bool);\n")
20421
0
SLANG_RAW("        };\n")
20422
0
SLANG_RAW("    }\n")
20423
0
SLANG_RAW("}\n")
20424
0
SLANG_RAW("\n")
20425
0
SLANG_RAW("/// @category raytracing\n")
20426
0
SLANG_RAW("[__requiresNVAPI]\n")
20427
0
SLANG_RAW("[NonUniformReturn]\n")
20428
0
SLANG_RAW("[require(cuda_hlsl_spirv, raytracing_lss)]\n")
20429
0
SLANG_RAW("bool IsLssHit()\n")
20430
0
SLANG_RAW("{\n")
20431
0
SLANG_RAW("    __target_switch\n")
20432
0
SLANG_RAW("    {\n")
20433
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvRtIsLssHit\";\n")
20434
0
SLANG_RAW("    case cuda:\n")
20435
0
SLANG_RAW("        {\n")
20436
0
SLANG_RAW("            __intrinsic_asm \"optixIsLSSHit\";\n")
20437
0
SLANG_RAW("        }\n")
20438
0
SLANG_RAW("    case spirv:\n")
20439
0
SLANG_RAW("        return spirv_asm\n")
20440
0
SLANG_RAW("        {\n")
20441
0
SLANG_RAW("            OpExtension \"SPV_NV_linear_swept_spheres\";\n")
20442
0
SLANG_RAW("            OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
20443
0
SLANG_RAW("            OpCapability RayTracingSpheresGeometryNV;\n")
20444
0
SLANG_RAW("            result:$$bool = OpLoad builtin(HitIsLSSNV:bool);\n")
20445
0
SLANG_RAW("        };\n")
20446
0
SLANG_RAW("    }\n")
20447
0
SLANG_RAW("}\n")
20448
0
SLANG_RAW("\n")
20449
0
SLANG_RAW("// Note: The provisional DXR spec included these unadorned\n")
20450
0
SLANG_RAW("// `ObjectToWorld()` and `WorldToObject()` functions, so\n")
20451
0
SLANG_RAW("// we will forward them to the new names as a convience\n")
20452
0
SLANG_RAW("// for users who are porting their code.\n")
20453
0
SLANG_RAW("//\n")
20454
0
SLANG_RAW("// TODO: Should we provide a deprecation warning on these\n")
20455
0
SLANG_RAW("// declarations, so that users can know they aren't coding\n")
20456
0
SLANG_RAW("// against the final spec?\n")
20457
0
SLANG_RAW("//\n")
20458
0
SLANG_RAW("/// Alias for ObjectToWorld3x4.\n")
20459
0
SLANG_RAW("/// @category raytracing\n")
20460
0
SLANG_RAW("[NonUniformReturn] float3x4 ObjectToWorld() { return ObjectToWorld3x4(); }\n")
20461
0
SLANG_RAW("/// Alias for WorldToObject3x4.\n")
20462
0
SLANG_RAW("/// @category raytracing\n")
20463
0
SLANG_RAW("[NonUniformReturn] float3x4 WorldToObject() { return WorldToObject3x4(); }\n")
20464
0
SLANG_RAW("\n")
20465
0
SLANG_RAW("// 10.4.4 - Hit Specific System values\n")
20466
0
SLANG_RAW("/// Returns the type of intersection that was found.\n")
20467
0
SLANG_RAW("/// @return Hit kind value (HIT_KIND_TRIANGLE_FRONT_FACE, HIT_KIND_TRIANGLE_BACK_FACE, or custom value)\n")
20468
0
SLANG_RAW("/// @remarks Available in any-hit and closest-hit shaders\n")
20469
0
SLANG_RAW("/// @category raytracing\n")
20470
0
SLANG_RAW("[NonUniformReturn]\n")
20471
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, raytracing_anyhit_closesthit)]\n")
20472
0
SLANG_RAW("uint HitKind()\n")
20473
0
SLANG_RAW("{\n")
20474
0
SLANG_RAW("    __target_switch\n")
20475
0
SLANG_RAW("    {\n")
20476
0
SLANG_RAW("    case hlsl:  __intrinsic_asm \"HitKind\";\n")
20477
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_HitKindEXT)\";\n")
20478
0
SLANG_RAW("    case cuda:  __intrinsic_asm \"optixGetHitKind\";\n")
20479
0
SLANG_RAW("    case spirv:\n")
20480
0
SLANG_RAW("        return spirv_asm\n")
20481
0
SLANG_RAW("        {\n")
20482
0
SLANG_RAW("            result:$$uint = OpLoad builtin(HitKindKHR:uint);\n")
20483
0
SLANG_RAW("        };\n")
20484
0
SLANG_RAW("    }\n")
20485
0
SLANG_RAW("}\n")
20486
0
SLANG_RAW("\n")
20487
0
SLANG_RAW("// Pre-defined hit kinds (not documented explicitly)\n")
20488
0
SLANG_RAW("/// Predefined hit kind value for front-facing triangle intersections.\n")
20489
0
SLANG_RAW("/// @category raytracing\n")
20490
0
SLANG_RAW("static const uint HIT_KIND_TRIANGLE_FRONT_FACE = 254;\n")
20491
0
SLANG_RAW("\n")
20492
0
SLANG_RAW("/// Predefined hit kind value for back-facing triangle intersections.\n")
20493
0
SLANG_RAW("/// @category raytracing\n")
20494
0
SLANG_RAW("static const uint HIT_KIND_TRIANGLE_BACK_FACE = 255;\n")
20495
0
SLANG_RAW("\n")
20496
0
SLANG_RAW("//\n")
20497
0
SLANG_RAW("// Shader Model 6.4\n")
20498
0
SLANG_RAW("// @public:\n")
20499
0
SLANG_RAW("//\n")
20500
0
SLANG_RAW("\n")
20501
0
SLANG_RAW("/// Treats `x` and `y` as 4-component vectors of `UInt8` and computes `dot(x, y) + acc`\n")
20502
0
SLANG_RAW("/// @category math\n")
20503
0
SLANG_RAW("[__readNone]\n")
20504
0
SLANG_RAW("[ForceInline]\n")
20505
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_6_4)]\n")
20506
0
SLANG_RAW("uint dot4add_u8packed(uint x, uint y, uint acc)\n")
20507
0
SLANG_RAW("{\n")
20508
0
SLANG_RAW("    __target_switch\n")
20509
0
SLANG_RAW("    {\n")
20510
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot4add_u8packed\";\n")
20511
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"(dot4U8Packed($0, $1) + $2)\";\n")
20512
0
SLANG_RAW("    case spirv:\n")
20513
0
SLANG_RAW("        // OpUDotAccSat cannot be used as there should not be any saturation.\n")
20514
0
SLANG_RAW("        return spirv_asm\n")
20515
0
SLANG_RAW("        {\n")
20516
0
SLANG_RAW("            OpCapability DotProduct;\n")
20517
0
SLANG_RAW("            OpCapability DotProductInput4x8BitPacked;\n")
20518
0
SLANG_RAW("            OpExtension \"SPV_KHR_integer_dot_product\";\n")
20519
0
SLANG_RAW("            %dotResult = OpUDot $$uint $x $y 0;\n")
20520
0
SLANG_RAW("            result:$$uint = OpIAdd %dotResult $acc;\n")
20521
0
SLANG_RAW("        };\n")
20522
0
SLANG_RAW("    default:\n")
20523
0
SLANG_RAW("        uint4 vecX = unpackUint4x8ToUint32(x);\n")
20524
0
SLANG_RAW("        uint4 vecY = unpackUint4x8ToUint32(y);\n")
20525
0
SLANG_RAW("        return dot(vecX, vecY) + acc;\n")
20526
0
SLANG_RAW("    }\n")
20527
0
SLANG_RAW("}\n")
20528
0
SLANG_RAW("\n")
20529
0
SLANG_RAW("/// Treats `x` and `y` as 4-component vectors of `int8` and computes `dot(x, y) + acc`\n")
20530
0
SLANG_RAW("/// @category math\n")
20531
0
SLANG_RAW("[__readNone]\n")
20532
0
SLANG_RAW("[ForceInline]\n")
20533
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_6_4)]\n")
20534
0
SLANG_RAW("int dot4add_i8packed(uint x, uint y, int acc)\n")
20535
0
SLANG_RAW("{\n")
20536
0
SLANG_RAW("    __target_switch\n")
20537
0
SLANG_RAW("    {\n")
20538
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot4add_i8packed\";\n")
20539
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"(dot4I8Packed($0, $1) + $2)\";\n")
20540
0
SLANG_RAW("    case spirv:\n")
20541
0
SLANG_RAW("        // OpSDottAccSat cannot be used as there should not be any saturation.\n")
20542
0
SLANG_RAW("        return spirv_asm\n")
20543
0
SLANG_RAW("        {\n")
20544
0
SLANG_RAW("            OpCapability DotProduct;\n")
20545
0
SLANG_RAW("            OpCapability DotProductInput4x8BitPacked;\n")
20546
0
SLANG_RAW("            OpExtension \"SPV_KHR_integer_dot_product\";\n")
20547
0
SLANG_RAW("            %dotResult = OpSDot $$int $x $y 0;\n")
20548
0
SLANG_RAW("            result:$$int = OpIAdd %dotResult $acc;\n")
20549
0
SLANG_RAW("        };\n")
20550
0
SLANG_RAW("    default:\n")
20551
0
SLANG_RAW("        int4 vecX = unpackInt4x8ToInt32(x);\n")
20552
0
SLANG_RAW("        int4 vecY = unpackInt4x8ToInt32(y);\n")
20553
0
SLANG_RAW("        return dot(vecX, vecY) + acc;\n")
20554
0
SLANG_RAW("    }\n")
20555
0
SLANG_RAW("}\n")
20556
0
SLANG_RAW("\n")
20557
0
SLANG_RAW("/// Computes `dot(x, y) + acc`.\n")
20558
0
SLANG_RAW("/// May not produce infinities or NaNs for intermediate results that overflow the range of `half`\n")
20559
0
SLANG_RAW("/// @category math\n")
20560
0
SLANG_RAW("[__readNone]\n")
20561
0
SLANG_RAW("[ForceInline]\n")
20562
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, sm_6_4)]\n")
20563
0
SLANG_RAW("float dot2add(half2 x, half2 y, float acc)\n")
20564
0
SLANG_RAW("{\n")
20565
0
SLANG_RAW("    __target_switch\n")
20566
0
SLANG_RAW("    {\n")
20567
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"dot2add\";\n")
20568
0
SLANG_RAW("    default:\n")
20569
0
SLANG_RAW("        return float(dot(x, y)) + acc;\n")
20570
0
SLANG_RAW("    }\n")
20571
0
SLANG_RAW("}\n")
20572
0
SLANG_RAW("\n")
20573
0
SLANG_RAW("//\n")
20574
0
SLANG_RAW("// Shader Model 6.5\n")
20575
0
SLANG_RAW("//\n")
20576
0
SLANG_RAW("\n")
20577
0
SLANG_RAW("//\n")
20578
0
SLANG_RAW("// Mesh Shaders\n")
20579
0
SLANG_RAW("//\n")
20580
0
SLANG_RAW("\n")
20581
0
SLANG_RAW("/// Set the number of output vertices and primitives for a mesh shader invocation.\n")
20582
0
SLANG_RAW("/// @category meshshading Mesh shading\n")
20583
0
SLANG_RAW("__glsl_extension(GL_EXT_mesh_shader)\n")
20584
0
SLANG_RAW("__glsl_version(450)\n")
20585
0
SLANG_RAW("[require(glsl_hlsl_metal_spirv, meshshading)]\n")
20586
0
SLANG_RAW("[noRefInline]\n")
20587
0
SLANG_RAW("void SetMeshOutputCounts(uint vertexCount, uint primitiveCount)\n")
20588
0
SLANG_RAW("{\n")
20589
0
SLANG_RAW("    __target_switch\n")
20590
0
SLANG_RAW("    {\n")
20591
0
SLANG_RAW("    case hlsl:\n")
20592
0
SLANG_RAW("        __intrinsic_asm \"SetMeshOutputCounts\";\n")
20593
0
SLANG_RAW("    case glsl:\n")
20594
0
SLANG_RAW("        __intrinsic_asm \"SetMeshOutputsEXT\";\n")
20595
0
SLANG_RAW("    case metal:\n")
20596
0
SLANG_RAW("        __intrinsic_asm \"_slang_mesh.set_primitive_count($1)\";\n")
20597
0
SLANG_RAW("    case spirv:\n")
20598
0
SLANG_RAW("        return spirv_asm\n")
20599
0
SLANG_RAW("        {\n")
20600
0
SLANG_RAW("            OpCapability MeshShadingEXT;\n")
20601
0
SLANG_RAW("            OpExtension \"SPV_EXT_mesh_shader\";\n")
20602
0
SLANG_RAW("            OpSetMeshOutputsEXT $vertexCount $primitiveCount;\n")
20603
0
SLANG_RAW("        };\n")
20604
0
SLANG_RAW("    }\n")
20605
0
SLANG_RAW("}\n")
20606
0
SLANG_RAW("\n")
20607
0
SLANG_RAW("/// Specify the number of downstream mesh shader thread groups to invoke from an amplification shader,\n")
20608
0
SLANG_RAW("/// and provide the values for per-mesh payload parameters.\n")
20609
0
SLANG_RAW("/// @return This function doesn't return.\n")
20610
0
SLANG_RAW("/// @category meshshading\n")
20611
0
SLANG_RAW("[KnownBuiltin(")
20612
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::DispatchMesh
20613
0
)
20614
0
SLANG_RAW(")]\n")
20615
0
SLANG_RAW("[require(glsl_hlsl_metal_spirv, meshshading)]\n")
20616
0
SLANG_RAW("[noRefInline]\n")
20617
0
SLANG_RAW("void DispatchMesh<P>(uint threadGroupCountX, uint threadGroupCountY, uint threadGroupCountZ, __ref P meshPayload)\n")
20618
0
SLANG_RAW("{\n")
20619
0
SLANG_RAW("    // This function cannot be inlined due to a legalization pass happening mid-way through processing\n")
20620
0
SLANG_RAW("    // and later more processing happening to the function which requires eventual inlining.\n")
20621
0
SLANG_RAW("    __target_switch\n")
20622
0
SLANG_RAW("    {\n")
20623
0
SLANG_RAW("    case hlsl:\n")
20624
0
SLANG_RAW("        __intrinsic_asm \"DispatchMesh\";\n")
20625
0
SLANG_RAW("    case glsl:\n")
20626
0
SLANG_RAW("        // This intrinsic doesn't take into account writing meshPayload. That\n")
20627
0
SLANG_RAW("        // is dealt with separately by 'legalizeDispatchMeshPayloadForGLSL'.\n")
20628
0
SLANG_RAW("        __intrinsic_asm \"EmitMeshTasksEXT($0, $1, $2)\";\n")
20629
0
SLANG_RAW("    case metal:\n")
20630
0
SLANG_RAW("        __intrinsic_asm \"*_slang_mesh_payload = *$3; _slang_mgp.set_threadgroups_per_grid(uint3($0, $1, $2)); return;\";\n")
20631
0
SLANG_RAW("    case spirv:\n")
20632
0
SLANG_RAW("        return spirv_asm\n")
20633
0
SLANG_RAW("        {\n")
20634
0
SLANG_RAW("            OpCapability MeshShadingEXT;\n")
20635
0
SLANG_RAW("            OpExtension \"SPV_EXT_mesh_shader\";\n")
20636
0
SLANG_RAW("            OpEmitMeshTasksEXT $threadGroupCountX $threadGroupCountY $threadGroupCountZ &meshPayload;\n")
20637
0
SLANG_RAW("            // OpEmitMeshTasksExt is a terminator, so we need to start a new\n")
20638
0
SLANG_RAW("            // block to hold whatever comes after this intrinsic\n")
20639
0
SLANG_RAW("            %_ = OpLabel\n")
20640
0
SLANG_RAW("        };\n")
20641
0
SLANG_RAW("    }\n")
20642
0
SLANG_RAW("}\n")
20643
0
SLANG_RAW("\n")
20644
0
SLANG_RAW("//\n")
20645
0
SLANG_RAW("// \"Sampler feedback\" types `FeedbackTexture2D` and `FeedbackTexture2DArray`.\n")
20646
0
SLANG_RAW("//\n")
20647
0
SLANG_RAW("\n")
20648
0
SLANG_RAW("// https://microsoft.github.io/DirectX-Specs/d3d/SamplerFeedback.html\n")
20649
0
SLANG_RAW("\n")
20650
0
SLANG_RAW("// The docs describe these as 'types' but their syntax makes them seem enum like, and enum is a simpler way to implement them\n")
20651
0
SLANG_RAW("// But slang enums are always 'enum class like', so I use an empty struct type here\n")
20652
0
SLANG_RAW("\n")
20653
0
SLANG_RAW("[sealed]\n")
20654
0
SLANG_RAW("[builtin]\n")
20655
0
SLANG_RAW("interface __BuiltinSamplerFeedbackType {};\n")
20656
0
SLANG_RAW("\n")
20657
0
SLANG_RAW("/// @category texture_types\n")
20658
0
SLANG_RAW("[sealed]\n")
20659
0
SLANG_RAW("__magic_type(FeedbackType, ")
20660
0
SLANG_SPLICE(int(FeedbackType::Kind::MinMip)
20661
0
)
20662
0
SLANG_RAW(")\n")
20663
0
SLANG_RAW("__target_intrinsic(hlsl, SAMPLER_FEEDBACK_MIN_MIP)\n")
20664
0
SLANG_RAW("struct SAMPLER_FEEDBACK_MIN_MIP : __BuiltinSamplerFeedbackType, ITexelElement {\n")
20665
0
SLANG_RAW("    typealias Element = float;\n")
20666
0
SLANG_RAW("    static const int elementCount = 1;\n")
20667
0
SLANG_RAW("    __intrinsic_op(0) __init(float x){}\n")
20668
0
SLANG_RAW("};\n")
20669
0
SLANG_RAW("\n")
20670
0
SLANG_RAW("/// @category texture_types\n")
20671
0
SLANG_RAW("[sealed]\n")
20672
0
SLANG_RAW("__magic_type(FeedbackType, ")
20673
0
SLANG_SPLICE(int(FeedbackType::Kind::MipRegionUsed)
20674
0
)
20675
0
SLANG_RAW(")\n")
20676
0
SLANG_RAW("__target_intrinsic(hlsl, SAMPLER_FEEDBACK_MIP_REGION_USED)\n")
20677
0
SLANG_RAW("struct SAMPLER_FEEDBACK_MIP_REGION_USED : __BuiltinSamplerFeedbackType, ITexelElement\n")
20678
0
SLANG_RAW("{\n")
20679
0
SLANG_RAW("    typealias Element = float;\n")
20680
0
SLANG_RAW("    static const int elementCount = 1;\n")
20681
0
SLANG_RAW("    __intrinsic_op(0) __init(float x){}\n")
20682
0
SLANG_RAW("};\n")
20683
0
SLANG_RAW("\n")
20684
0
SLANG_RAW("// All of these objects are write-only resources that point to a special kind of unordered access view meant for sampler feedback.\n")
20685
0
SLANG_RAW("\n")
20686
0
SLANG_RAW("extension<T> _Texture<T,__Shape2D, 0, 0, 0, ")
20687
0
SLANG_SPLICE(kCoreModule_ResourceAccessFeedback
20688
0
)
20689
0
SLANG_RAW(", 0, 0, 0>\n")
20690
0
SLANG_RAW("    where T:ITexelElement\n")
20691
0
SLANG_RAW("    where T:__BuiltinSamplerFeedbackType\n")
20692
0
SLANG_RAW("{\n")
20693
0
SLANG_RAW("    // With Clamp\n")
20694
0
SLANG_RAW("\n")
20695
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20696
0
SLANG_RAW("    void WriteSamplerFeedback<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float clamp)\n")
20697
0
SLANG_RAW("    {\n")
20698
0
SLANG_RAW("        __target_switch\n")
20699
0
SLANG_RAW("        {\n")
20700
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3, $4)\";\n")
20701
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3, $4)\";\n")
20702
0
SLANG_RAW("        }\n")
20703
0
SLANG_RAW("    }\n")
20704
0
SLANG_RAW("\n")
20705
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20706
0
SLANG_RAW("    void WriteSamplerFeedbackBias<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float bias, float clamp)\n")
20707
0
SLANG_RAW("    {\n")
20708
0
SLANG_RAW("        __target_switch\n")
20709
0
SLANG_RAW("        {\n")
20710
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4, $5)\";\n")
20711
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4, $5)\";\n")
20712
0
SLANG_RAW("        }\n")
20713
0
SLANG_RAW("    }\n")
20714
0
SLANG_RAW("\n")
20715
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20716
0
SLANG_RAW("    void WriteSamplerFeedbackGrad<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float2 ddx, float2 ddy, float clamp)\n")
20717
0
SLANG_RAW("    {\n")
20718
0
SLANG_RAW("        __target_switch\n")
20719
0
SLANG_RAW("        {\n")
20720
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5, $6)\";\n")
20721
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5, $6)\";\n")
20722
0
SLANG_RAW("        }\n")
20723
0
SLANG_RAW("    }\n")
20724
0
SLANG_RAW("\n")
20725
0
SLANG_RAW("    // Level\n")
20726
0
SLANG_RAW("\n")
20727
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20728
0
SLANG_RAW("    void WriteSamplerFeedbackLevel<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float lod)\n")
20729
0
SLANG_RAW("    {\n")
20730
0
SLANG_RAW("        __target_switch\n")
20731
0
SLANG_RAW("        {\n")
20732
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackLevel($1, $2, $3, $4)\";\n")
20733
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackLevel($1, $2, $3, $4)\";\n")
20734
0
SLANG_RAW("        }\n")
20735
0
SLANG_RAW("    }\n")
20736
0
SLANG_RAW("\n")
20737
0
SLANG_RAW("    // Without Clamp\n")
20738
0
SLANG_RAW("\n")
20739
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20740
0
SLANG_RAW("    void WriteSamplerFeedback<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location)\n")
20741
0
SLANG_RAW("    {\n")
20742
0
SLANG_RAW("        __target_switch\n")
20743
0
SLANG_RAW("        {\n")
20744
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3)\";\n")
20745
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3)\";\n")
20746
0
SLANG_RAW("        }\n")
20747
0
SLANG_RAW("    }\n")
20748
0
SLANG_RAW("\n")
20749
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20750
0
SLANG_RAW("    void WriteSamplerFeedbackBias<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float bias)\n")
20751
0
SLANG_RAW("    {\n")
20752
0
SLANG_RAW("        __target_switch\n")
20753
0
SLANG_RAW("        {\n")
20754
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4)\";\n")
20755
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4)\";\n")
20756
0
SLANG_RAW("        }\n")
20757
0
SLANG_RAW("    }\n")
20758
0
SLANG_RAW("\n")
20759
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20760
0
SLANG_RAW("    void WriteSamplerFeedbackGrad<S:ITexelElement>(Texture2D<S> tex, SamplerState samp, float2 location, float2 ddx, float2 ddy)\n")
20761
0
SLANG_RAW("    {\n")
20762
0
SLANG_RAW("        __target_switch\n")
20763
0
SLANG_RAW("        {\n")
20764
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5)\";\n")
20765
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5)\";\n")
20766
0
SLANG_RAW("        }\n")
20767
0
SLANG_RAW("    }\n")
20768
0
SLANG_RAW("};\n")
20769
0
SLANG_RAW("\n")
20770
0
SLANG_RAW("extension<T> _Texture<T,__Shape2D, 1, 0, 0, ")
20771
0
SLANG_SPLICE(kCoreModule_ResourceAccessFeedback
20772
0
)
20773
0
SLANG_RAW(", 0, 0, 0>\n")
20774
0
SLANG_RAW("    where T:__BuiltinSamplerFeedbackType\n")
20775
0
SLANG_RAW("    where T:ITexelElement\n")
20776
0
SLANG_RAW("{\n")
20777
0
SLANG_RAW("    // With Clamp\n")
20778
0
SLANG_RAW("\n")
20779
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20780
0
SLANG_RAW("    void WriteSamplerFeedback<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float clamp)\n")
20781
0
SLANG_RAW("    {\n")
20782
0
SLANG_RAW("        __target_switch\n")
20783
0
SLANG_RAW("        {\n")
20784
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3, $4)\";\n")
20785
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3, $4)\";\n")
20786
0
SLANG_RAW("        }\n")
20787
0
SLANG_RAW("    }\n")
20788
0
SLANG_RAW("\n")
20789
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20790
0
SLANG_RAW("    void WriteSamplerFeedbackBias<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float bias, float clamp)\n")
20791
0
SLANG_RAW("    {\n")
20792
0
SLANG_RAW("        __target_switch\n")
20793
0
SLANG_RAW("        {\n")
20794
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4, $5)\";\n")
20795
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4, $5)\";\n")
20796
0
SLANG_RAW("        }\n")
20797
0
SLANG_RAW("    }\n")
20798
0
SLANG_RAW("\n")
20799
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20800
0
SLANG_RAW("    void WriteSamplerFeedbackGrad<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float3 ddx, float3 ddy, float clamp)\n")
20801
0
SLANG_RAW("    {\n")
20802
0
SLANG_RAW("        __target_switch\n")
20803
0
SLANG_RAW("        {\n")
20804
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5, $6)\";\n")
20805
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5, $6)\";\n")
20806
0
SLANG_RAW("        }\n")
20807
0
SLANG_RAW("    }\n")
20808
0
SLANG_RAW("\n")
20809
0
SLANG_RAW("    // Level\n")
20810
0
SLANG_RAW("\n")
20811
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20812
0
SLANG_RAW("    void WriteSamplerFeedbackLevel<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float lod)\n")
20813
0
SLANG_RAW("    {\n")
20814
0
SLANG_RAW("        __target_switch\n")
20815
0
SLANG_RAW("        {\n")
20816
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackLevel($1, $2, $3, $4)\";\n")
20817
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackLevel($1, $2, $3, $4)\";\n")
20818
0
SLANG_RAW("        }\n")
20819
0
SLANG_RAW("    }\n")
20820
0
SLANG_RAW("\n")
20821
0
SLANG_RAW("    // Without Clamp\n")
20822
0
SLANG_RAW("\n")
20823
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20824
0
SLANG_RAW("    void WriteSamplerFeedback<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location)\n")
20825
0
SLANG_RAW("    {\n")
20826
0
SLANG_RAW("        __target_switch\n")
20827
0
SLANG_RAW("        {\n")
20828
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3)\";\n")
20829
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedback($1, $2, $3)\";\n")
20830
0
SLANG_RAW("        }\n")
20831
0
SLANG_RAW("    }\n")
20832
0
SLANG_RAW("\n")
20833
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20834
0
SLANG_RAW("    void WriteSamplerFeedbackBias<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float bias)\n")
20835
0
SLANG_RAW("    {\n")
20836
0
SLANG_RAW("        __target_switch\n")
20837
0
SLANG_RAW("        {\n")
20838
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4)\";\n")
20839
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackBias($1, $2, $3, $4)\";\n")
20840
0
SLANG_RAW("        }\n")
20841
0
SLANG_RAW("    }\n")
20842
0
SLANG_RAW("\n")
20843
0
SLANG_RAW("    [require(cpp_hlsl)]\n")
20844
0
SLANG_RAW("    void WriteSamplerFeedbackGrad<S:ITexelElement>(Texture2DArray<S> texArray, SamplerState samp, float3 location, float3 ddx, float3 ddy)\n")
20845
0
SLANG_RAW("    {\n")
20846
0
SLANG_RAW("        __target_switch\n")
20847
0
SLANG_RAW("        {\n")
20848
0
SLANG_RAW("        case cpp: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5)\";\n")
20849
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($0).WriteSamplerFeedbackGrad($1, $2, $3, $4, $5)\";\n")
20850
0
SLANG_RAW("        }\n")
20851
0
SLANG_RAW("    }\n")
20852
0
SLANG_RAW("};\n")
20853
0
SLANG_RAW("\n")
20854
0
SLANG_RAW("//\n")
20855
0
SLANG_RAW("// DXR 1.1 and `TraceRayInline` support\n")
20856
0
SLANG_RAW("//\n")
20857
0
SLANG_RAW("\n")
20858
0
SLANG_RAW("/// Returns the index of the geometry that was hit in an intersection, any-hit, or closest-hit shader.\n")
20859
0
SLANG_RAW("/// @return Zero-based index of the geometry in the current instance\n")
20860
0
SLANG_RAW("/// @remarks Available in intersection, any-hit, and closest-hit shaders\n")
20861
0
SLANG_RAW("/// @category raytracing\n")
20862
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
20863
0
SLANG_RAW("[NonUniformReturn]\n")
20864
0
SLANG_RAW("[require(glsl_hlsl_spirv, raytracing_anyhit_closesthit_intersection)]\n")
20865
0
SLANG_RAW("uint GeometryIndex()\n")
20866
0
SLANG_RAW("{\n")
20867
0
SLANG_RAW("    __target_switch\n")
20868
0
SLANG_RAW("    {\n")
20869
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"GeometryIndex\";\n")
20870
0
SLANG_RAW("    case glsl: __intrinsic_asm \"(gl_GeometryIndexEXT)\";\n")
20871
0
SLANG_RAW("    case spirv: return spirv_asm {\n")
20872
0
SLANG_RAW("            result:$$uint = OpLoad builtin(RayGeometryIndexKHR:uint);\n")
20873
0
SLANG_RAW("        };\n")
20874
0
SLANG_RAW("    }\n")
20875
0
SLANG_RAW("}\n")
20876
0
SLANG_RAW("\n")
20877
0
SLANG_RAW("/// Get the vertex positions of the currently hit triangle in any-hit or closest-hit shader.\n")
20878
0
SLANG_RAW("/// https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing_position_fetch.txt\n")
20879
0
SLANG_RAW("/// @param index Index of the vertex (0-2)\n")
20880
0
SLANG_RAW("/// @return World-space position of the specified vertex\n")
20881
0
SLANG_RAW("/// @remarks Requires ray tracing position fetch extension\n")
20882
0
SLANG_RAW("/// @see GL_EXT_ray_tracing_position_fetch\n")
20883
0
SLANG_RAW("/// @category raytracing\n")
20884
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
20885
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing_position_fetch)\n")
20886
0
SLANG_RAW("[ForceInline]\n")
20887
0
SLANG_RAW("[require(glsl_spirv, raytracing_position)]\n")
20888
0
SLANG_RAW("float3 HitTriangleVertexPosition(uint index)\n")
20889
0
SLANG_RAW("{\n")
20890
0
SLANG_RAW("    __target_switch\n")
20891
0
SLANG_RAW("    {\n")
20892
0
SLANG_RAW("        case glsl:\n")
20893
0
SLANG_RAW("            __intrinsic_asm \"gl_HitTriangleVertexPositionsEXT[$0]\";\n")
20894
0
SLANG_RAW("        case spirv:\n")
20895
0
SLANG_RAW("            return spirv_asm {\n")
20896
0
SLANG_RAW("                OpCapability RayTracingKHR;\n")
20897
0
SLANG_RAW("                OpCapability RayTracingPositionFetchKHR;\n")
20898
0
SLANG_RAW("                OpExtension \"SPV_KHR_ray_tracing\";\n")
20899
0
SLANG_RAW("                OpExtension \"SPV_KHR_ray_tracing_position_fetch\";\n")
20900
0
SLANG_RAW("                %_ptr_Input_v3float = OpTypePointer Input $$float3;\n")
20901
0
SLANG_RAW("                %addr : %_ptr_Input_v3float = OpAccessChain builtin(HitTriangleVertexPositionsKHR:float3[3]) $index;\n")
20902
0
SLANG_RAW("                result:$$float3 = OpLoad %addr;\n")
20903
0
SLANG_RAW("            };\n")
20904
0
SLANG_RAW("    }\n")
20905
0
SLANG_RAW("}\n")
20906
0
SLANG_RAW("\n")
20907
0
SLANG_RAW("/// Status indicating whether and what type of hit has been committed in a RayQuery.\n")
20908
0
SLANG_RAW("/// @category raytracing\n")
20909
0
SLANG_RAW("typedef uint COMMITTED_STATUS;\n")
20910
0
SLANG_RAW("\n")
20911
0
SLANG_RAW("/// Indicates no hit has been committed yet.\n")
20912
0
SLANG_RAW("/// @category raytracing\n")
20913
0
SLANG_RAW("static const COMMITTED_STATUS COMMITTED_NOTHING = 0;\n")
20914
0
SLANG_RAW("\n")
20915
0
SLANG_RAW("/// Closest hit is a triangle.\n")
20916
0
SLANG_RAW("/// This could be an opaque triangle hit found by the fixed-function\n")
20917
0
SLANG_RAW("/// traversal and intersection implementation, or a non-opaque\n")
20918
0
SLANG_RAW("/// triangle hit committed by user code with `RayQuery.CommitNonOpaqueTriangleHit`.\n")
20919
0
SLANG_RAW("/// @category raytracing\n")
20920
0
SLANG_RAW("static const COMMITTED_STATUS COMMITTED_TRIANGLE_HIT = 1;\n")
20921
0
SLANG_RAW("\n")
20922
0
SLANG_RAW("/// Closest hit is a procedural primitive.\n")
20923
0
SLANG_RAW("/// A procedural hit primitive is committed using `RayQuery.CommitProceduralPrimitiveHit`.\n")
20924
0
SLANG_RAW("/// @category raytracing\n")
20925
0
SLANG_RAW("static const COMMITTED_STATUS COMMITTED_PROCEDURAL_PRIMITIVE_HIT = 2;\n")
20926
0
SLANG_RAW("\n")
20927
0
SLANG_RAW("/// Type of candidate hit that a `RayQuery` is pausing at.\n")
20928
0
SLANG_RAW("/// A `RayQuery` can automatically commit hits with opaque triangles,\n")
20929
0
SLANG_RAW("/// but yields to user code for other hits to allow them to be\n")
20930
0
SLANG_RAW("/// dismissed or committed.\n")
20931
0
SLANG_RAW("/// @category raytracing\n")
20932
0
SLANG_RAW("typedef uint CANDIDATE_TYPE;\n")
20933
0
SLANG_RAW("\n")
20934
0
SLANG_RAW("/// Candidate hit is a non-opaque triangle.\n")
20935
0
SLANG_RAW("/// @category raytracing\n")
20936
0
SLANG_RAW("static const CANDIDATE_TYPE CANDIDATE_NON_OPAQUE_TRIANGLE = 0;\n")
20937
0
SLANG_RAW("\n")
20938
0
SLANG_RAW("/// Candidate hit is a procedural primitive.\n")
20939
0
SLANG_RAW("/// @category raytracing\n")
20940
0
SLANG_RAW("static const CANDIDATE_TYPE CANDIDATE_PROCEDURAL_PRIMITIVE = 1;\n")
20941
0
SLANG_RAW("\n")
20942
0
SLANG_RAW("/// Handle to state of an in-progress ray-tracing query.\n")
20943
0
SLANG_RAW("/// The ray query is effectively a coroutine that user shader\n")
20944
0
SLANG_RAW("/// code can resume to continue tracing the ray, and which yields\n")
20945
0
SLANG_RAW("/// back to the user code at interesting events along the ray.\n")
20946
0
SLANG_RAW("//\n")
20947
0
SLANG_RAW("/// Note: The treatment of the `RayQuery` type in Slang does not\n")
20948
0
SLANG_RAW("/// perfectly match its semantics in vanilla HLSL in some corner\n")
20949
0
SLANG_RAW("/// cases. Specifically, a `RayQuery` in vanilla HLSL is an\n")
20950
0
SLANG_RAW("/// opaque handle to mutable storage, and assigning a `RayQuery`\n")
20951
0
SLANG_RAW("/// or passing one as a parameter will only copy the *handle*,\n")
20952
0
SLANG_RAW("/// potentially resulting in aliasing of the underlying mutable\n")
20953
0
SLANG_RAW("/// storage.\n")
20954
0
SLANG_RAW("///\n")
20955
0
SLANG_RAW("/// In contrast, Slang considers a `RayQuery` to own its mutable\n")
20956
0
SLANG_RAW("/// state, and (because the API does not support cloning of queries),\n")
20957
0
SLANG_RAW("/// `RayQuery` values are non-copyable (aka \"move-only\").\n")
20958
0
SLANG_RAW("///\n")
20959
0
SLANG_RAW("/// The main place where this arises as a consideration is when\n")
20960
0
SLANG_RAW("/// passing a `RayQuery` down into a function that will perform\n")
20961
0
SLANG_RAW("/// mutating operations on it (e.g., `TraceRay` or `Proceed`):\n")
20962
0
SLANG_RAW("/// ```\n")
20963
0
SLANG_RAW("///      void myFunc( inout RayQuery<FLAGS> q )\n")
20964
0
SLANG_RAW("///      {\n")
20965
0
SLANG_RAW("///          q.Proceed();\n")
20966
0
SLANG_RAW("///      }\n")
20967
0
SLANG_RAW("/// ```\n")
20968
0
SLANG_RAW("/// In Slang, a parameter like `q` above should be declared `inout`.\n")
20969
0
SLANG_RAW("/// HLSL does not care about whether `q` is declared `inout` or not.\n")
20970
0
SLANG_RAW("///\n")
20971
0
SLANG_RAW("///cannot use a cap for struct with unequal target support\n")
20972
0
SLANG_RAW("///since it will propegate rules to children.\n")
20973
0
SLANG_RAW("/// @category raytracing Ray-tracing\n")
20974
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_query)\n")
20975
0
SLANG_RAW("[__NonCopyableType]\n")
20976
0
SLANG_RAW("__intrinsic_type(")
20977
0
SLANG_SPLICE(kIROp_RayQueryType
20978
0
)
20979
0
SLANG_RAW(")\n")
20980
0
SLANG_RAW("struct RayQuery <let rayFlagsGeneric : RAY_FLAG = RAY_FLAG_NONE>\n")
20981
0
SLANG_RAW("{\n")
20982
0
SLANG_RAW("    /// Initialize a new ray query in its default state.\n")
20983
0
SLANG_RAW("    __intrinsic_op(")
20984
0
SLANG_SPLICE(kIROp_AllocateOpaqueHandle
20985
0
)
20986
0
SLANG_RAW(")\n")
20987
0
SLANG_RAW("    __init();\n")
20988
0
SLANG_RAW("\n")
20989
0
SLANG_RAW("\n")
20990
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
20991
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
20992
0
SLANG_RAW("    [mutating]\n")
20993
0
SLANG_RAW("    void __rayQueryInitializeEXT(\n")
20994
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
20995
0
SLANG_RAW("        RAY_FLAG                        rayFlags,\n")
20996
0
SLANG_RAW("        uint                            instanceInclusionMask,\n")
20997
0
SLANG_RAW("        float3                          origin,\n")
20998
0
SLANG_RAW("        float                           tMin,\n")
20999
0
SLANG_RAW("        float3                          direction,\n")
21000
0
SLANG_RAW("        float                           tMax)\n")
21001
0
SLANG_RAW("    {\n")
21002
0
SLANG_RAW("        __target_switch\n")
21003
0
SLANG_RAW("        {\n")
21004
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryInitializeEXT($0, $1, $2, $3, $4, $5, $6, $7)\";\n")
21005
0
SLANG_RAW("        case spirv:\n")
21006
0
SLANG_RAW("            spirv_asm {\n")
21007
0
SLANG_RAW("                OpRayQueryInitializeKHR &this $accelerationStructure $rayFlags $instanceInclusionMask $origin $tMin $direction $tMax;\n")
21008
0
SLANG_RAW("            };\n")
21009
0
SLANG_RAW("        }\n")
21010
0
SLANG_RAW("    }\n")
21011
0
SLANG_RAW("\n")
21012
0
SLANG_RAW("    /// Initialize a ray-tracing query.\n")
21013
0
SLANG_RAW("    ///\n")
21014
0
SLANG_RAW("    /// This method may be called on a \"fresh\" ray query, or\n")
21015
0
SLANG_RAW("    /// on one that is already tracing a ray. In the latter\n")
21016
0
SLANG_RAW("    /// case any state related to the ray previously being\n")
21017
0
SLANG_RAW("    /// traced is overwritten.\n")
21018
0
SLANG_RAW("    ///\n")
21019
0
SLANG_RAW("    /// The `rayFlags` here will be bitwise ORed with\n")
21020
0
SLANG_RAW("    /// the `rayFlags` passed as a generic argument to\n")
21021
0
SLANG_RAW("    /// `RayQuery` to get the effective ray flags, which\n")
21022
0
SLANG_RAW("    /// must obey any API-imposed restrictions.\n")
21023
0
SLANG_RAW("    ///\n")
21024
0
SLANG_RAW("    /// @param accelerationStructure Acceleration structure to traverse\n")
21025
0
SLANG_RAW("    /// @param rayFlags Additional flags for this trace (combined with rayFlagsGeneric)\n")
21026
0
SLANG_RAW("    /// @param instanceInclusionMask Mask for filtering instance visibility\n")
21027
0
SLANG_RAW("    /// @param ray Description of ray parameters (origin, direction, tMin, tMax)\n")
21028
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
21029
0
SLANG_RAW("    [mutating]\n")
21030
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21031
0
SLANG_RAW("    void TraceRayInline(\n")
21032
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
21033
0
SLANG_RAW("        RAY_FLAG                        rayFlags,\n")
21034
0
SLANG_RAW("        uint                            instanceInclusionMask,\n")
21035
0
SLANG_RAW("        RayDesc                         ray)\n")
21036
0
SLANG_RAW("    {\n")
21037
0
SLANG_RAW("        __target_switch\n")
21038
0
SLANG_RAW("        {\n")
21039
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".TraceRayInline\";\n")
21040
0
SLANG_RAW("        case glsl:\n")
21041
0
SLANG_RAW("        case spirv:\n")
21042
0
SLANG_RAW("            __rayQueryInitializeEXT(\n")
21043
0
SLANG_RAW("                accelerationStructure,\n")
21044
0
SLANG_RAW("                rayFlags | rayFlagsGeneric,\n")
21045
0
SLANG_RAW("                instanceInclusionMask,\n")
21046
0
SLANG_RAW("                ray.Origin,\n")
21047
0
SLANG_RAW("                ray.TMin,\n")
21048
0
SLANG_RAW("                ray.Direction,\n")
21049
0
SLANG_RAW("                ray.TMax);\n")
21050
0
SLANG_RAW("        }\n")
21051
0
SLANG_RAW("    }\n")
21052
0
SLANG_RAW("\n")
21053
0
SLANG_RAW("    /// Resume the ray query coroutine.\n")
21054
0
SLANG_RAW("    ///\n")
21055
0
SLANG_RAW("    /// If the coroutine suspends because of encountering\n")
21056
0
SLANG_RAW("    /// a candidate hit that cannot be resolved with fixed-funciton\n")
21057
0
SLANG_RAW("    /// logic, this function returns `true`, and the `Candidate*()`\n")
21058
0
SLANG_RAW("    /// functions should be used by application code to resolve\n")
21059
0
SLANG_RAW("    /// the candidate hit (by either committing or ignoring it).\n")
21060
0
SLANG_RAW("    ///\n")
21061
0
SLANG_RAW("    /// If the coroutine terminates because traversal is\n")
21062
0
SLANG_RAW("    /// complete (or has been aborted), this function returns\n")
21063
0
SLANG_RAW("    /// `false`, and application code should use the `Committed*()`\n")
21064
0
SLANG_RAW("    /// functions to appropriately handle the closest hit (it any)\n")
21065
0
SLANG_RAW("    /// that was found.\n")
21066
0
SLANG_RAW("    ///\n")
21067
0
SLANG_RAW("    /// @return true if a candidate hit needs evaluation, false if traversal is complete\n")
21068
0
SLANG_RAW("    /// @remarks When true is returned, use Candidate* methods to evaluate the hit\n")
21069
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21070
0
SLANG_RAW("    [mutating]\n")
21071
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21072
0
SLANG_RAW("    bool Proceed()\n")
21073
0
SLANG_RAW("    {\n")
21074
0
SLANG_RAW("        __target_switch\n")
21075
0
SLANG_RAW("        {\n")
21076
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Proceed\";\n")
21077
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryProceedEXT\";\n")
21078
0
SLANG_RAW("        case spirv: return spirv_asm\n")
21079
0
SLANG_RAW("            {\n")
21080
0
SLANG_RAW("                result:$$bool = OpRayQueryProceedKHR &this\n")
21081
0
SLANG_RAW("            };\n")
21082
0
SLANG_RAW("        }\n")
21083
0
SLANG_RAW("    }\n")
21084
0
SLANG_RAW("\n")
21085
0
SLANG_RAW("    /// Terminate ray traversal immediately.\n")
21086
0
SLANG_RAW("    /// @remarks Causes subsequent Proceed() calls to return false\n")
21087
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21088
0
SLANG_RAW("    [mutating]\n")
21089
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21090
0
SLANG_RAW("    void Abort()\n")
21091
0
SLANG_RAW("    {\n")
21092
0
SLANG_RAW("        __target_switch\n")
21093
0
SLANG_RAW("        {\n")
21094
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".Abort\";\n")
21095
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryTerminateEXT\";\n")
21096
0
SLANG_RAW("        case spirv: spirv_asm { OpRayQueryTerminateKHR &this };\n")
21097
0
SLANG_RAW("        }\n")
21098
0
SLANG_RAW("    }\n")
21099
0
SLANG_RAW("\n")
21100
0
SLANG_RAW("    /// Commit the current non-opaque triangle hit as the closest hit.\n")
21101
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21102
0
SLANG_RAW("    [__NoSideEffect]\n")
21103
0
SLANG_RAW("    [mutating]\n")
21104
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21105
0
SLANG_RAW("    void CommitNonOpaqueTriangleHit()\n")
21106
0
SLANG_RAW("    {\n")
21107
0
SLANG_RAW("        __target_switch\n")
21108
0
SLANG_RAW("        {\n")
21109
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CommitNonOpaqueTriangleHit\";\n")
21110
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryConfirmIntersectionEXT\";\n")
21111
0
SLANG_RAW("        case spirv: spirv_asm { OpRayQueryConfirmIntersectionKHR &this };\n")
21112
0
SLANG_RAW("        }\n")
21113
0
SLANG_RAW("    }\n")
21114
0
SLANG_RAW("\n")
21115
0
SLANG_RAW("    /// Commit a procedural primitive hit at the specified distance.\n")
21116
0
SLANG_RAW("    /// @param t Distance along the ray where the hit occurred\n")
21117
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21118
0
SLANG_RAW("    [__NoSideEffect]\n")
21119
0
SLANG_RAW("    [mutating]\n")
21120
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21121
0
SLANG_RAW("    void CommitProceduralPrimitiveHit(float t)\n")
21122
0
SLANG_RAW("    {\n")
21123
0
SLANG_RAW("        __target_switch\n")
21124
0
SLANG_RAW("        {\n")
21125
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CommitProceduralPrimitiveHit\";\n")
21126
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGenerateIntersectionEXT\";\n")
21127
0
SLANG_RAW("        case spirv: spirv_asm { OpRayQueryGenerateIntersectionKHR &this $t };\n")
21128
0
SLANG_RAW("        }\n")
21129
0
SLANG_RAW("    }\n")
21130
0
SLANG_RAW("\n")
21131
0
SLANG_RAW("    /// Get the type of candidate hit being considered.\n")
21132
0
SLANG_RAW("    ///\n")
21133
0
SLANG_RAW("    /// The ray query coroutine will suspend when it encounters\n")
21134
0
SLANG_RAW("    /// a hit that cannot be resolved with fixed-function logic\n")
21135
0
SLANG_RAW("    /// (either a non-opaque triangle or a procedural primitive).\n")
21136
0
SLANG_RAW("    /// In either of those cases, `CandidateType()` will return\n")
21137
0
SLANG_RAW("    /// the kind of candidate hit that must be resolved by\n")
21138
0
SLANG_RAW("    /// user code.\n")
21139
0
SLANG_RAW("    ///\n")
21140
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21141
0
SLANG_RAW("    [__NoSideEffect]\n")
21142
0
SLANG_RAW("    [NonUniformReturn]\n")
21143
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21144
0
SLANG_RAW("    CANDIDATE_TYPE CandidateType()\n")
21145
0
SLANG_RAW("    {\n")
21146
0
SLANG_RAW("        __target_switch\n")
21147
0
SLANG_RAW("        {\n")
21148
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CandidateType\";\n")
21149
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionTypeEXT($0, false)\";\n")
21150
0
SLANG_RAW("        case spirv:\n")
21151
0
SLANG_RAW("            uint RayQueryCandidateIntersectionKHR = 0;\n")
21152
0
SLANG_RAW("            return spirv_asm {\n")
21153
0
SLANG_RAW("                result:$$CANDIDATE_TYPE = OpRayQueryGetIntersectionTypeKHR &this $RayQueryCandidateIntersectionKHR;\n")
21154
0
SLANG_RAW("            };\n")
21155
0
SLANG_RAW("        }\n")
21156
0
SLANG_RAW("    }\n")
21157
0
SLANG_RAW("\n")
21158
0
SLANG_RAW("    /// Returns the status of the committed (closest) hit.\n")
21159
0
SLANG_RAW("    /// @return COMMITTED_STATUS indicating type of committed hit, if any\n")
21160
0
SLANG_RAW("    /// @remarks Valid after traversal is complete (Proceed() returns false)\n")
21161
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21162
0
SLANG_RAW("    [__NoSideEffect]\n")
21163
0
SLANG_RAW("    [NonUniformReturn]\n")
21164
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21165
0
SLANG_RAW("    COMMITTED_STATUS CommittedStatus()\n")
21166
0
SLANG_RAW("    {\n")
21167
0
SLANG_RAW("        __target_switch\n")
21168
0
SLANG_RAW("        {\n")
21169
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CommittedStatus\";\n")
21170
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionTypeEXT($0, true)\";\n")
21171
0
SLANG_RAW("        case spirv:\n")
21172
0
SLANG_RAW("            uint RayQueryCommittedIntersectionKHR = 1;\n")
21173
0
SLANG_RAW("            return spirv_asm\n")
21174
0
SLANG_RAW("            {\n")
21175
0
SLANG_RAW("                result:$$COMMITTED_STATUS = OpRayQueryGetIntersectionTypeKHR &this $RayQueryCommittedIntersectionKHR;\n")
21176
0
SLANG_RAW("            };\n")
21177
0
SLANG_RAW("        }\n")
21178
0
SLANG_RAW("    }\n")
21179
0
SLANG_RAW("\n")
21180
0
SLANG_RAW("    /// Checks if the candidate procedural primitive is non-opaque.\n")
21181
0
SLANG_RAW("    /// @return true if the primitive is non-opaque and requires shader evaluation\n")
21182
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21183
0
SLANG_RAW("    [__NoSideEffect]\n")
21184
0
SLANG_RAW("    [NonUniformReturn]\n")
21185
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21186
0
SLANG_RAW("    bool CandidateProceduralPrimitiveNonOpaque()\n")
21187
0
SLANG_RAW("    {\n")
21188
0
SLANG_RAW("        __target_switch\n")
21189
0
SLANG_RAW("        {\n")
21190
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CandidateProceduralPrimitiveNonOpaque\";\n")
21191
0
SLANG_RAW("        case glsl: __intrinsic_asm \"(!rayQueryGetIntersectionCandidateAABBOpaqueEXT($0))\";\n")
21192
0
SLANG_RAW("        case spirv:\n")
21193
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21194
0
SLANG_RAW("            return spirv_asm\n")
21195
0
SLANG_RAW("            {\n")
21196
0
SLANG_RAW("                %rr:$$bool = OpRayQueryGetIntersectionCandidateAABBOpaqueKHR &this;\n")
21197
0
SLANG_RAW("                result:$$bool = OpLogicalNot %rr;\n")
21198
0
SLANG_RAW("            };\n")
21199
0
SLANG_RAW("        }\n")
21200
0
SLANG_RAW("    }\n")
21201
0
SLANG_RAW("\n")
21202
0
SLANG_RAW("    /// Gets the distance to the candidate triangle hit.\n")
21203
0
SLANG_RAW("    /// @return t-value along the ray where intersection occurred\n")
21204
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21205
0
SLANG_RAW("    [__NoSideEffect]\n")
21206
0
SLANG_RAW("    [NonUniformReturn]\n")
21207
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21208
0
SLANG_RAW("    float CandidateTriangleRayT()\n")
21209
0
SLANG_RAW("    {\n")
21210
0
SLANG_RAW("        __target_switch\n")
21211
0
SLANG_RAW("        {\n")
21212
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CandidateTriangleRayT\";\n")
21213
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionTEXT($0, false)\";\n")
21214
0
SLANG_RAW("        case spirv:\n")
21215
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21216
0
SLANG_RAW("            return spirv_asm\n")
21217
0
SLANG_RAW("            {\n")
21218
0
SLANG_RAW("                result:$$float = OpRayQueryGetIntersectionTKHR &this $iCandidateOrCommitted;\n")
21219
0
SLANG_RAW("            };\n")
21220
0
SLANG_RAW("        }\n")
21221
0
SLANG_RAW("    }\n")
21222
0
SLANG_RAW("\n")
21223
0
SLANG_RAW("    /// Gets the distance to the committed (closest) hit.\n")
21224
0
SLANG_RAW("    /// @return t-value along the ray where the closest hit occurred\n")
21225
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21226
0
SLANG_RAW("    [__NoSideEffect]\n")
21227
0
SLANG_RAW("    [NonUniformReturn]\n")
21228
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21229
0
SLANG_RAW("    float CommittedRayT()\n")
21230
0
SLANG_RAW("    {\n")
21231
0
SLANG_RAW("        __target_switch\n")
21232
0
SLANG_RAW("        {\n")
21233
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".CommittedRayT\";\n")
21234
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionTEXT($0, true)\";\n")
21235
0
SLANG_RAW("        case spirv:\n")
21236
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21237
0
SLANG_RAW("            return spirv_asm\n")
21238
0
SLANG_RAW("            {\n")
21239
0
SLANG_RAW("                result:$$float = OpRayQueryGetIntersectionTKHR &this $iCandidateOrCommitted;\n")
21240
0
SLANG_RAW("            };\n")
21241
0
SLANG_RAW("        }\n")
21242
0
SLANG_RAW("    }\n")
21243
0
SLANG_RAW("\n")
21244
0
SLANG_RAW("    /// Gets the custom index of the instance containing the candidate hit.\n")
21245
0
SLANG_RAW("    /// @return User-provided instance identifier\n")
21246
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21247
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21248
0
SLANG_RAW("    [__NoSideEffect]\n")
21249
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21250
0
SLANG_RAW("    int CandidateRayInstanceCustomIndex()\n")
21251
0
SLANG_RAW("    {\n")
21252
0
SLANG_RAW("        __target_switch\n")
21253
0
SLANG_RAW("        {\n")
21254
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceCustomIndexEXT($0, false)\";\n")
21255
0
SLANG_RAW("        case spirv:\n")
21256
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21257
0
SLANG_RAW("            return spirv_asm\n")
21258
0
SLANG_RAW("            {\n")
21259
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionInstanceCustomIndexKHR &this $iCandidateOrCommitted;\n")
21260
0
SLANG_RAW("            };\n")
21261
0
SLANG_RAW("        }\n")
21262
0
SLANG_RAW("    }\n")
21263
0
SLANG_RAW("\n")
21264
0
SLANG_RAW("    /// Gets the cluster ID of the candidate hit.\n")
21265
0
SLANG_RAW("    /// @return Cluster ID for the candidate hit\n")
21266
0
SLANG_RAW("    /// @remarks HLSL/GLSL/SPIRV\n")
21267
0
SLANG_RAW("    [__requiresNVAPI]\n")
21268
0
SLANG_RAW("    __glsl_extension(GL_NV_cluster_acceleration_structure)\n")
21269
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21270
0
SLANG_RAW("    [__NoSideEffect]\n")
21271
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21272
0
SLANG_RAW("    int CandidateClusterID()\n")
21273
0
SLANG_RAW("    {\n")
21274
0
SLANG_RAW("        __target_switch\n")
21275
0
SLANG_RAW("        {\n")
21276
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvRtGetCandidateClusterID\";\n")
21277
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionClusterIdNV($0, false)\";\n")
21278
0
SLANG_RAW("        case spirv:\n")
21279
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21280
0
SLANG_RAW("            return spirv_asm\n")
21281
0
SLANG_RAW("            {\n")
21282
0
SLANG_RAW("                OpExtension \"SPV_NV_cluster_acceleration_structure\";\n")
21283
0
SLANG_RAW("                OpCapability RayTracingClusterAccelerationStructureNV;\n")
21284
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionClusterIdNV &this $iCandidateOrCommitted;\n")
21285
0
SLANG_RAW("            };\n")
21286
0
SLANG_RAW("        }\n")
21287
0
SLANG_RAW("    }\n")
21288
0
SLANG_RAW("\n")
21289
0
SLANG_RAW("    /// Gets the custom index of the instance containing the committed hit.\n")
21290
0
SLANG_RAW("    /// @return User-provided instance identifier\n")
21291
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21292
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21293
0
SLANG_RAW("    [__NoSideEffect]\n")
21294
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21295
0
SLANG_RAW("    int CommittedRayInstanceCustomIndex()\n")
21296
0
SLANG_RAW("    {\n")
21297
0
SLANG_RAW("        __target_switch\n")
21298
0
SLANG_RAW("        {\n")
21299
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceCustomIndexEXT($0, true)\";\n")
21300
0
SLANG_RAW("        case spirv:\n")
21301
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21302
0
SLANG_RAW("            return spirv_asm\n")
21303
0
SLANG_RAW("            {\n")
21304
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionInstanceCustomIndexKHR &this $iCandidateOrCommitted;\n")
21305
0
SLANG_RAW("            };\n")
21306
0
SLANG_RAW("        }\n")
21307
0
SLANG_RAW("    }\n")
21308
0
SLANG_RAW("\n")
21309
0
SLANG_RAW("    /// Gets the cluster ID of the committed hit.\n")
21310
0
SLANG_RAW("    /// @return Cluster ID for the committed hit\n")
21311
0
SLANG_RAW("    /// @remarks HLSL/GLSL/SPIRV\n")
21312
0
SLANG_RAW("    [__requiresNVAPI]\n")
21313
0
SLANG_RAW("    __glsl_extension(GL_NV_cluster_acceleration_structure)\n")
21314
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21315
0
SLANG_RAW("    [__NoSideEffect]\n")
21316
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21317
0
SLANG_RAW("    int CommittedClusterID()\n")
21318
0
SLANG_RAW("    {\n")
21319
0
SLANG_RAW("        __target_switch\n")
21320
0
SLANG_RAW("        {\n")
21321
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvRtGetCommittedClusterID\";\n")
21322
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionClusterIdNV($0, true)\";\n")
21323
0
SLANG_RAW("        case spirv:\n")
21324
0
SLANG_RAW("            uint iCandidateOrCommitted = 1; // 1 for committed\n")
21325
0
SLANG_RAW("            return spirv_asm\n")
21326
0
SLANG_RAW("            {\n")
21327
0
SLANG_RAW("                OpExtension \"SPV_NV_cluster_acceleration_structure\";\n")
21328
0
SLANG_RAW("                OpCapability RayTracingClusterAccelerationStructureNV;\n")
21329
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionClusterIdNV &this $iCandidateOrCommitted;\n")
21330
0
SLANG_RAW("            };\n")
21331
0
SLANG_RAW("        }\n")
21332
0
SLANG_RAW("    }\n")
21333
0
SLANG_RAW("\n")
21334
0
SLANG_RAW("    /// Gets the instance ID of the candidate hit.\n")
21335
0
SLANG_RAW("    /// @return System-assigned instance identifier\n")
21336
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21337
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21338
0
SLANG_RAW("    [__NoSideEffect]\n")
21339
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21340
0
SLANG_RAW("    int CandidateRayInstanceId()\n")
21341
0
SLANG_RAW("    {\n")
21342
0
SLANG_RAW("        __target_switch\n")
21343
0
SLANG_RAW("        {\n")
21344
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceIdEXT($0, false)\";\n")
21345
0
SLANG_RAW("        case spirv:\n")
21346
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21347
0
SLANG_RAW("            return spirv_asm\n")
21348
0
SLANG_RAW("            {\n")
21349
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionInstanceIdKHR &this $iCandidateOrCommitted;\n")
21350
0
SLANG_RAW("            };\n")
21351
0
SLANG_RAW("        }\n")
21352
0
SLANG_RAW("    }\n")
21353
0
SLANG_RAW("\n")
21354
0
SLANG_RAW("    /// Gets the instance ID of the committed hit.\n")
21355
0
SLANG_RAW("    /// @return System-assigned instance identifier\n")
21356
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21357
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21358
0
SLANG_RAW("    [__NoSideEffect]\n")
21359
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21360
0
SLANG_RAW("    int CommittedRayInstanceId()\n")
21361
0
SLANG_RAW("    {\n")
21362
0
SLANG_RAW("        __target_switch\n")
21363
0
SLANG_RAW("        {\n")
21364
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceIdEXT($0, true)\";\n")
21365
0
SLANG_RAW("        case spirv:\n")
21366
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21367
0
SLANG_RAW("            return spirv_asm\n")
21368
0
SLANG_RAW("            {\n")
21369
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionInstanceIdKHR &this $iCandidateOrCommitted;\n")
21370
0
SLANG_RAW("            };\n")
21371
0
SLANG_RAW("        }\n")
21372
0
SLANG_RAW("    }\n")
21373
0
SLANG_RAW("\n")
21374
0
SLANG_RAW("    /// Gets the shader binding table offset for the instance containing the candidate hit.\n")
21375
0
SLANG_RAW("    /// @return Offset into the shader binding table for hit group selection\n")
21376
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21377
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21378
0
SLANG_RAW("    [__NoSideEffect]\n")
21379
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21380
0
SLANG_RAW("    uint CandidateRayInstanceShaderBindingTableRecordOffset()\n")
21381
0
SLANG_RAW("    {\n")
21382
0
SLANG_RAW("        __target_switch\n")
21383
0
SLANG_RAW("        {\n")
21384
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, false)\";\n")
21385
0
SLANG_RAW("        case spirv:\n")
21386
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21387
0
SLANG_RAW("            return spirv_asm\n")
21388
0
SLANG_RAW("            {\n")
21389
0
SLANG_RAW("                result:$$uint = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR &this $iCandidateOrCommitted;\n")
21390
0
SLANG_RAW("            };\n")
21391
0
SLANG_RAW("        }\n")
21392
0
SLANG_RAW("    }\n")
21393
0
SLANG_RAW("\n")
21394
0
SLANG_RAW("    /// Gets the shader binding table offset for the instance containing the committed hit.\n")
21395
0
SLANG_RAW("    /// @return Offset into the shader binding table for hit group selection\n")
21396
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21397
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21398
0
SLANG_RAW("    [__NoSideEffect]\n")
21399
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21400
0
SLANG_RAW("    uint CommittedRayInstanceShaderBindingTableRecordOffset()\n")
21401
0
SLANG_RAW("    {\n")
21402
0
SLANG_RAW("        __target_switch\n")
21403
0
SLANG_RAW("        {\n")
21404
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, true)\";\n")
21405
0
SLANG_RAW("        case spirv:\n")
21406
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21407
0
SLANG_RAW("            return spirv_asm\n")
21408
0
SLANG_RAW("            {\n")
21409
0
SLANG_RAW("                result:$$uint = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR &this $iCandidateOrCommitted;\n")
21410
0
SLANG_RAW("            };\n")
21411
0
SLANG_RAW("        }\n")
21412
0
SLANG_RAW("    }\n")
21413
0
SLANG_RAW("\n")
21414
0
SLANG_RAW("    /// Gets the geometry index for the candidate hit.\n")
21415
0
SLANG_RAW("    /// @return Zero-based index of the geometry in the instance\n")
21416
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21417
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21418
0
SLANG_RAW("    [__NoSideEffect]\n")
21419
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21420
0
SLANG_RAW("    int CandidateRayGeometryIndex()\n")
21421
0
SLANG_RAW("    {\n")
21422
0
SLANG_RAW("        __target_switch\n")
21423
0
SLANG_RAW("        {\n")
21424
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionGeometryIndexEXT($0, false)\";\n")
21425
0
SLANG_RAW("        case spirv:\n")
21426
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21427
0
SLANG_RAW("            return spirv_asm\n")
21428
0
SLANG_RAW("            {\n")
21429
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionGeometryIndexKHR &this $iCandidateOrCommitted;\n")
21430
0
SLANG_RAW("            };\n")
21431
0
SLANG_RAW("        }\n")
21432
0
SLANG_RAW("    }\n")
21433
0
SLANG_RAW("\n")
21434
0
SLANG_RAW("    /// Gets the geometry index for the committed hit.\n")
21435
0
SLANG_RAW("    /// @return Zero-based index of the geometry in the instance\n")
21436
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21437
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21438
0
SLANG_RAW("    [__NoSideEffect]\n")
21439
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21440
0
SLANG_RAW("    int CommittedRayGeometryIndex()\n")
21441
0
SLANG_RAW("    {\n")
21442
0
SLANG_RAW("        __target_switch\n")
21443
0
SLANG_RAW("        {\n")
21444
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionGeometryIndexEXT($0, true)\";\n")
21445
0
SLANG_RAW("        case spirv:\n")
21446
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21447
0
SLANG_RAW("            return spirv_asm\n")
21448
0
SLANG_RAW("            {\n")
21449
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionGeometryIndexKHR &this $iCandidateOrCommitted;\n")
21450
0
SLANG_RAW("            };\n")
21451
0
SLANG_RAW("        }\n")
21452
0
SLANG_RAW("    }\n")
21453
0
SLANG_RAW("\n")
21454
0
SLANG_RAW("    /// Gets the primitive index for the candidate hit.\n")
21455
0
SLANG_RAW("    /// @return Zero-based index of the primitive in the geometry\n")
21456
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21457
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21458
0
SLANG_RAW("    [__NoSideEffect]\n")
21459
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21460
0
SLANG_RAW("    int CandidateRayPrimitiveIndex()\n")
21461
0
SLANG_RAW("    {\n")
21462
0
SLANG_RAW("        __target_switch\n")
21463
0
SLANG_RAW("        {\n")
21464
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionPrimitiveIndexEXT($0, false)\";\n")
21465
0
SLANG_RAW("        case spirv:\n")
21466
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21467
0
SLANG_RAW("            return spirv_asm\n")
21468
0
SLANG_RAW("            {\n")
21469
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionPrimitiveIndexKHR &this $iCandidateOrCommitted;\n")
21470
0
SLANG_RAW("            };\n")
21471
0
SLANG_RAW("        }\n")
21472
0
SLANG_RAW("    }\n")
21473
0
SLANG_RAW("\n")
21474
0
SLANG_RAW("    /// Gets the primitive index for the committed hit.\n")
21475
0
SLANG_RAW("    /// @return Zero-based index of the primitive in the geometry\n")
21476
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21477
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21478
0
SLANG_RAW("    [__NoSideEffect]\n")
21479
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21480
0
SLANG_RAW("    int CommittedRayPrimitiveIndex()\n")
21481
0
SLANG_RAW("    {\n")
21482
0
SLANG_RAW("        __target_switch\n")
21483
0
SLANG_RAW("        {\n")
21484
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionPrimitiveIndexEXT($0, true)\";\n")
21485
0
SLANG_RAW("        case spirv:\n")
21486
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21487
0
SLANG_RAW("            return spirv_asm\n")
21488
0
SLANG_RAW("            {\n")
21489
0
SLANG_RAW("                result:$$int = OpRayQueryGetIntersectionPrimitiveIndexKHR &this $iCandidateOrCommitted;\n")
21490
0
SLANG_RAW("            };\n")
21491
0
SLANG_RAW("        }\n")
21492
0
SLANG_RAW("    }\n")
21493
0
SLANG_RAW("\n")
21494
0
SLANG_RAW("    /// Gets the barycentric coordinates of the candidate hit point.\n")
21495
0
SLANG_RAW("    /// @return UV barycentric coordinates on the triangle\n")
21496
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21497
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21498
0
SLANG_RAW("    [__NoSideEffect]\n")
21499
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21500
0
SLANG_RAW("    float2 CandidateRayBarycentrics()\n")
21501
0
SLANG_RAW("    {\n")
21502
0
SLANG_RAW("        __target_switch\n")
21503
0
SLANG_RAW("        {\n")
21504
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionBarycentricsEXT($0, false)\";\n")
21505
0
SLANG_RAW("        case spirv:\n")
21506
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21507
0
SLANG_RAW("            return spirv_asm\n")
21508
0
SLANG_RAW("            {\n")
21509
0
SLANG_RAW("                result:$$float2 = OpRayQueryGetIntersectionBarycentricsKHR &this $iCandidateOrCommitted;\n")
21510
0
SLANG_RAW("            };\n")
21511
0
SLANG_RAW("        }\n")
21512
0
SLANG_RAW("    }\n")
21513
0
SLANG_RAW("\n")
21514
0
SLANG_RAW("    /// Gets the barycentric coordinates of the committed hit point.\n")
21515
0
SLANG_RAW("    /// @return UV barycentric coordinates on the triangle\n")
21516
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21517
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21518
0
SLANG_RAW("    [__NoSideEffect]\n")
21519
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21520
0
SLANG_RAW("    float2 CommittedRayBarycentrics()\n")
21521
0
SLANG_RAW("    {\n")
21522
0
SLANG_RAW("        __target_switch\n")
21523
0
SLANG_RAW("        {\n")
21524
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionBarycentricsEXT($0, true)\";\n")
21525
0
SLANG_RAW("        case spirv:\n")
21526
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21527
0
SLANG_RAW("            return spirv_asm\n")
21528
0
SLANG_RAW("            {\n")
21529
0
SLANG_RAW("                result:$$float2 = OpRayQueryGetIntersectionBarycentricsKHR &this $iCandidateOrCommitted;\n")
21530
0
SLANG_RAW("            };\n")
21531
0
SLANG_RAW("        }\n")
21532
0
SLANG_RAW("    }\n")
21533
0
SLANG_RAW("\n")
21534
0
SLANG_RAW("    /// Checks if the candidate hit is on the front face of a triangle.\n")
21535
0
SLANG_RAW("    /// @return true if hit is on triangle front face\n")
21536
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21537
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21538
0
SLANG_RAW("    [__NoSideEffect]\n")
21539
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21540
0
SLANG_RAW("    bool CandidateRayFrontFace()\n")
21541
0
SLANG_RAW("    {\n")
21542
0
SLANG_RAW("        __target_switch\n")
21543
0
SLANG_RAW("        {\n")
21544
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionFrontFaceEXT($0, false)\";\n")
21545
0
SLANG_RAW("        case spirv:\n")
21546
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21547
0
SLANG_RAW("            return spirv_asm\n")
21548
0
SLANG_RAW("            {\n")
21549
0
SLANG_RAW("                result:$$bool = OpRayQueryGetIntersectionFrontFaceKHR &this $iCandidateOrCommitted;\n")
21550
0
SLANG_RAW("            };\n")
21551
0
SLANG_RAW("        }\n")
21552
0
SLANG_RAW("    }\n")
21553
0
SLANG_RAW("\n")
21554
0
SLANG_RAW("    /// Checks if the committed hit is on the front face of a triangle.\n")
21555
0
SLANG_RAW("    /// @return true if hit is on triangle front face\n")
21556
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21557
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21558
0
SLANG_RAW("    [__NoSideEffect]\n")
21559
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21560
0
SLANG_RAW("    bool CommittedRayFrontFace()\n")
21561
0
SLANG_RAW("    {\n")
21562
0
SLANG_RAW("        __target_switch\n")
21563
0
SLANG_RAW("        {\n")
21564
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionFrontFaceEXT($0, true)\";\n")
21565
0
SLANG_RAW("        case spirv:\n")
21566
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21567
0
SLANG_RAW("            return spirv_asm\n")
21568
0
SLANG_RAW("            {\n")
21569
0
SLANG_RAW("                result:$$bool = OpRayQueryGetIntersectionFrontFaceKHR &this $iCandidateOrCommitted;\n")
21570
0
SLANG_RAW("            };\n")
21571
0
SLANG_RAW("        }\n")
21572
0
SLANG_RAW("    }\n")
21573
0
SLANG_RAW("\n")
21574
0
SLANG_RAW("    /// Gets the ray direction in object space for the candidate hit.\n")
21575
0
SLANG_RAW("    /// @return Direction vector transformed into instance's object space\n")
21576
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21577
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21578
0
SLANG_RAW("    [__NoSideEffect]\n")
21579
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21580
0
SLANG_RAW("    float3 CandidateRayObjectRayDirection()\n")
21581
0
SLANG_RAW("    {\n")
21582
0
SLANG_RAW("        __target_switch\n")
21583
0
SLANG_RAW("        {\n")
21584
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectRayDirectionEXT($0, false)\";\n")
21585
0
SLANG_RAW("        case spirv:\n")
21586
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21587
0
SLANG_RAW("            return spirv_asm\n")
21588
0
SLANG_RAW("            {\n")
21589
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetIntersectionObjectRayDirectionKHR &this $iCandidateOrCommitted;\n")
21590
0
SLANG_RAW("            };\n")
21591
0
SLANG_RAW("        }\n")
21592
0
SLANG_RAW("    }\n")
21593
0
SLANG_RAW("\n")
21594
0
SLANG_RAW("    /// Gets the ray direction in object space for the committed hit.\n")
21595
0
SLANG_RAW("    /// @return Direction vector transformed into instance's object space\n")
21596
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21597
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21598
0
SLANG_RAW("    [__NoSideEffect]\n")
21599
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21600
0
SLANG_RAW("    float3 CommittedRayObjectRayDirection()\n")
21601
0
SLANG_RAW("    {\n")
21602
0
SLANG_RAW("        __target_switch\n")
21603
0
SLANG_RAW("        {\n")
21604
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectRayDirectionEXT($0, true)\";\n")
21605
0
SLANG_RAW("        case spirv:\n")
21606
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21607
0
SLANG_RAW("            return spirv_asm\n")
21608
0
SLANG_RAW("            {\n")
21609
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetIntersectionObjectRayDirectionKHR &this $iCandidateOrCommitted;\n")
21610
0
SLANG_RAW("            };\n")
21611
0
SLANG_RAW("        }\n")
21612
0
SLANG_RAW("    }\n")
21613
0
SLANG_RAW("\n")
21614
0
SLANG_RAW("    /// Gets the ray origin in object space for the candidate hit.\n")
21615
0
SLANG_RAW("    /// @return Origin point transformed into instance's object space\n")
21616
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21617
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21618
0
SLANG_RAW("    [__NoSideEffect]\n")
21619
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21620
0
SLANG_RAW("    float3 CandidateRayObjectRayOrigin()\n")
21621
0
SLANG_RAW("    {\n")
21622
0
SLANG_RAW("        __target_switch\n")
21623
0
SLANG_RAW("        {\n")
21624
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectRayOriginEXT($0, false)\";\n")
21625
0
SLANG_RAW("        case spirv:\n")
21626
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21627
0
SLANG_RAW("            return spirv_asm\n")
21628
0
SLANG_RAW("            {\n")
21629
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetIntersectionObjectRayOriginKHR &this $iCandidateOrCommitted;\n")
21630
0
SLANG_RAW("            };\n")
21631
0
SLANG_RAW("        }\n")
21632
0
SLANG_RAW("    }\n")
21633
0
SLANG_RAW("\n")
21634
0
SLANG_RAW("    /// Gets the ray origin in object space for the committed hit.\n")
21635
0
SLANG_RAW("    /// @return Origin point transformed into instance's object space\n")
21636
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21637
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21638
0
SLANG_RAW("    [__NoSideEffect]\n")
21639
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21640
0
SLANG_RAW("    float3 CommittedRayObjectRayOrigin()\n")
21641
0
SLANG_RAW("    {\n")
21642
0
SLANG_RAW("        __target_switch\n")
21643
0
SLANG_RAW("        {\n")
21644
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectRayOriginEXT($0, true)\";\n")
21645
0
SLANG_RAW("        case spirv:\n")
21646
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21647
0
SLANG_RAW("            return spirv_asm\n")
21648
0
SLANG_RAW("            {\n")
21649
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetIntersectionObjectRayOriginKHR &this $iCandidateOrCommitted;\n")
21650
0
SLANG_RAW("            };\n")
21651
0
SLANG_RAW("        }\n")
21652
0
SLANG_RAW("    }\n")
21653
0
SLANG_RAW("\n")
21654
0
SLANG_RAW("    /// Gets the object-to-world transform matrix for the candidate hit instance.\n")
21655
0
SLANG_RAW("    /// @return 4x3 matrix transforming from object to world space\n")
21656
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21657
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21658
0
SLANG_RAW("    [__NoSideEffect]\n")
21659
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21660
0
SLANG_RAW("    float4x3 CandidateRayObjectToWorld()\n")
21661
0
SLANG_RAW("    {\n")
21662
0
SLANG_RAW("        __target_switch\n")
21663
0
SLANG_RAW("        {\n")
21664
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectToWorldEXT($0, false)\";\n")
21665
0
SLANG_RAW("        case spirv:\n")
21666
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21667
0
SLANG_RAW("            return spirv_asm\n")
21668
0
SLANG_RAW("            {\n")
21669
0
SLANG_RAW("                result:$$float4x3 = OpRayQueryGetIntersectionObjectToWorldKHR &this $iCandidateOrCommitted;\n")
21670
0
SLANG_RAW("            };\n")
21671
0
SLANG_RAW("        }\n")
21672
0
SLANG_RAW("    }\n")
21673
0
SLANG_RAW("\n")
21674
0
SLANG_RAW("    /// Gets the object-to-world transform matrix for the committed hit instance.\n")
21675
0
SLANG_RAW("    /// @return 4x3 matrix transforming from object to world space\n")
21676
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21677
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21678
0
SLANG_RAW("    [__NoSideEffect]\n")
21679
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21680
0
SLANG_RAW("    float4x3 CommittedRayObjectToWorld()\n")
21681
0
SLANG_RAW("    {\n")
21682
0
SLANG_RAW("        __target_switch\n")
21683
0
SLANG_RAW("        {\n")
21684
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionObjectToWorldEXT($0, true)\";\n")
21685
0
SLANG_RAW("        case spirv:\n")
21686
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21687
0
SLANG_RAW("            return spirv_asm\n")
21688
0
SLANG_RAW("            {\n")
21689
0
SLANG_RAW("                result:$$float4x3 = OpRayQueryGetIntersectionObjectToWorldKHR &this $iCandidateOrCommitted;\n")
21690
0
SLANG_RAW("            };\n")
21691
0
SLANG_RAW("        }\n")
21692
0
SLANG_RAW("    }\n")
21693
0
SLANG_RAW("\n")
21694
0
SLANG_RAW("    /// Gets the world-to-object transform matrix for the candidate hit instance.\n")
21695
0
SLANG_RAW("    /// @return 4x3 matrix transforming from world to object space\n")
21696
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21697
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21698
0
SLANG_RAW("    [__NoSideEffect]\n")
21699
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21700
0
SLANG_RAW("    float4x3 CandidateRayWorldToObject()\n")
21701
0
SLANG_RAW("    {\n")
21702
0
SLANG_RAW("        __target_switch\n")
21703
0
SLANG_RAW("        {\n")
21704
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionWorldToObjectEXT($0, false)\";\n")
21705
0
SLANG_RAW("        case spirv:\n")
21706
0
SLANG_RAW("            uint iCandidateOrCommitted = 0;\n")
21707
0
SLANG_RAW("            return spirv_asm\n")
21708
0
SLANG_RAW("            {\n")
21709
0
SLANG_RAW("                result:$$float4x3 = OpRayQueryGetIntersectionWorldToObjectKHR &this $iCandidateOrCommitted;\n")
21710
0
SLANG_RAW("            };\n")
21711
0
SLANG_RAW("        }\n")
21712
0
SLANG_RAW("    }\n")
21713
0
SLANG_RAW("\n")
21714
0
SLANG_RAW("    /// Gets the world-to-object transform matrix for the committed hit instance.\n")
21715
0
SLANG_RAW("    /// @return 4x3 matrix transforming from world to object space\n")
21716
0
SLANG_RAW("    /// @remarks GLSL/SPIRV only\n")
21717
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21718
0
SLANG_RAW("    [__NoSideEffect]\n")
21719
0
SLANG_RAW("    [require(glsl_spirv, rayquery)]\n")
21720
0
SLANG_RAW("    float4x3 CommittedRayWorldToObject()\n")
21721
0
SLANG_RAW("    {\n")
21722
0
SLANG_RAW("        __target_switch\n")
21723
0
SLANG_RAW("        {\n")
21724
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersectionWorldToObjectEXT($0, true)\";\n")
21725
0
SLANG_RAW("        case spirv:\n")
21726
0
SLANG_RAW("            uint iCandidateOrCommitted = 1;\n")
21727
0
SLANG_RAW("            return spirv_asm\n")
21728
0
SLANG_RAW("            {\n")
21729
0
SLANG_RAW("                OpRayQueryGetIntersectionWorldToObjectKHR $$float4x3 result &this $iCandidateOrCommitted;\n")
21730
0
SLANG_RAW("            };\n")
21731
0
SLANG_RAW("        }\n")
21732
0
SLANG_RAW("    }\n")
21733
0
SLANG_RAW("///~\n")
21734
0
SLANG_RAW("\n")
21735
21736
0
    const char* kCandidateCommitted[] = {"Candidate", "Committed"};
21737
21738
    // Access Candidate and Committed Matrices.
21739
0
    for (uint32_t candidateOrCommitted = 0; candidateOrCommitted < 2; candidateOrCommitted++)
21740
0
    {
21741
0
        auto ccName = kCandidateCommitted[candidateOrCommitted];
21742
0
        auto ccTF = candidateOrCommitted == 0 ? "false" : "true";
21743
0
SLANG_RAW("#line 19679 \"hlsl.meta.slang\"")
21744
0
SLANG_RAW("\n")
21745
0
SLANG_RAW("\n")
21746
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21747
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing_position_fetch)\n")
21748
0
SLANG_RAW("    [require(glsl, rayquery_position)]\n")
21749
0
SLANG_RAW("    [__NoSideEffect]\n")
21750
0
SLANG_RAW("    void __glslGetIntersectionTriangleVertexPositions")
21751
0
SLANG_SPLICE(ccName
21752
0
)
21753
0
SLANG_RAW("(out float3 arr[3])\n")
21754
0
SLANG_RAW("    {\n")
21755
0
SLANG_RAW("        __intrinsic_asm \"rayQueryGetIntersectionTriangleVertexPositionsEXT($0, ")
21756
0
SLANG_SPLICE(ccTF
21757
0
)
21758
0
SLANG_RAW(", $1)\";\n")
21759
0
SLANG_RAW("    };\n")
21760
0
SLANG_RAW("\n")
21761
0
SLANG_RAW("    /// Gets the triangle vertex positions for an intersection.\n")
21762
0
SLANG_RAW("    /// @return Array of three vertex positions in world space\n")
21763
0
SLANG_RAW("    /// @remarks Requires ray query position fetch extension\n")
21764
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21765
0
SLANG_RAW("    [require(glsl, rayquery_position)]\n")
21766
0
SLANG_RAW("    [require(spirv, rayquery_position)]\n")
21767
0
SLANG_RAW("    [__NoSideEffect]\n")
21768
0
SLANG_RAW("    float3[3] ")
21769
0
SLANG_SPLICE(ccName
21770
0
)
21771
0
SLANG_RAW("GetIntersectionTriangleVertexPositions()\n")
21772
0
SLANG_RAW("    {\n")
21773
0
SLANG_RAW("        typedef float3[3] float3Arr3;\n")
21774
0
SLANG_RAW("        __target_switch\n")
21775
0
SLANG_RAW("        {\n")
21776
0
SLANG_RAW("        case glsl:\n")
21777
0
SLANG_RAW("            float3 output[3];\n")
21778
0
SLANG_RAW("            __glslGetIntersectionTriangleVertexPositions")
21779
0
SLANG_SPLICE(ccName
21780
0
)
21781
0
SLANG_RAW("(output);\n")
21782
0
SLANG_RAW("            return output;\n")
21783
0
SLANG_RAW("        case spirv:\n")
21784
0
SLANG_RAW("            uint iCandidateOrCommitted = ")
21785
0
SLANG_SPLICE(candidateOrCommitted
21786
0
)
21787
0
SLANG_RAW(";\n")
21788
0
SLANG_RAW("            return spirv_asm\n")
21789
0
SLANG_RAW("            {\n")
21790
0
SLANG_RAW("                OpCapability RayQueryKHR;\n")
21791
0
SLANG_RAW("                OpCapability RayQueryPositionFetchKHR;\n")
21792
0
SLANG_RAW("                OpExtension \"SPV_KHR_ray_query\";\n")
21793
0
SLANG_RAW("                OpExtension \"SPV_KHR_ray_tracing_position_fetch\";\n")
21794
0
SLANG_RAW("                result: $$float3Arr3 = OpRayQueryGetIntersectionTriangleVertexPositionsKHR &this $iCandidateOrCommitted;\n")
21795
0
SLANG_RAW("            };\n")
21796
0
SLANG_RAW("        }\n")
21797
0
SLANG_RAW("    };\n")
21798
0
SLANG_RAW("\n")
21799
0
SLANG_RAW("    // CandidateObjectToWorld3x4, CandidateWorldToObject4x3\n")
21800
0
SLANG_RAW("    // CommittedObjectToWorld3x4, CommittedObjectToWorld4x3\n")
21801
21802
0
    const char* kRayQueryMatrixNames[] = {"ObjectToWorld", "WorldToObject"};
21803
0
    for (auto matName : kRayQueryMatrixNames) {
21804
    
21805
0
SLANG_RAW("#line 19724 \"hlsl.meta.slang\"")
21806
0
SLANG_RAW("\n")
21807
0
SLANG_RAW("\n")
21808
0
SLANG_RAW("    /// Gets the object-to-world transform as a 3x4 matrix.\n")
21809
0
SLANG_RAW("    /// @return 3x4 matrix transforming from object to world space\n")
21810
0
SLANG_RAW("    /// @remarks Available for both candidate and committed hits\n")
21811
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21812
0
SLANG_RAW("    [__NoSideEffect]\n")
21813
0
SLANG_RAW("    [NonUniformReturn]\n")
21814
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21815
0
SLANG_RAW("    float3x4 ")
21816
0
SLANG_SPLICE(ccName
21817
0
)
21818
0
SLANG_SPLICE(matName
21819
0
)
21820
0
SLANG_RAW("3x4()\n")
21821
0
SLANG_RAW("    {\n")
21822
0
SLANG_RAW("        __target_switch\n")
21823
0
SLANG_RAW("        {\n")
21824
0
SLANG_RAW("        case glsl: __intrinsic_asm \"transpose(rayQueryGetIntersection")
21825
0
SLANG_SPLICE(matName
21826
0
)
21827
0
SLANG_RAW("EXT($0, ")
21828
0
SLANG_SPLICE(ccTF
21829
0
)
21830
0
SLANG_RAW("))\";\n")
21831
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".")
21832
0
SLANG_SPLICE(ccName
21833
0
)
21834
0
SLANG_SPLICE(matName
21835
0
)
21836
0
SLANG_RAW("3x4\";\n")
21837
0
SLANG_RAW("        case spirv:\n")
21838
0
SLANG_RAW("            uint iCandidateOrCommitted = ")
21839
0
SLANG_SPLICE(candidateOrCommitted
21840
0
)
21841
0
SLANG_RAW(";\n")
21842
0
SLANG_RAW("            return spirv_asm\n")
21843
0
SLANG_RAW("            {\n")
21844
0
SLANG_RAW("                %m:$$float4x3 = OpRayQueryGetIntersection")
21845
0
SLANG_SPLICE(matName
21846
0
)
21847
0
SLANG_RAW("KHR &this $iCandidateOrCommitted;\n")
21848
0
SLANG_RAW("                result:$$float3x4 = OpTranspose %m;\n")
21849
0
SLANG_RAW("            };\n")
21850
0
SLANG_RAW("        }\n")
21851
0
SLANG_RAW("    }\n")
21852
0
SLANG_RAW("\n")
21853
0
SLANG_RAW("    /// Gets the world-to-object transform as a 4x3 matrix.\n")
21854
0
SLANG_RAW("    /// @return 4x3 matrix transforming from world to object space\n")
21855
0
SLANG_RAW("    /// @remarks Available for both candidate and committed hits\n")
21856
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21857
0
SLANG_RAW("    [__readNone]\n")
21858
0
SLANG_RAW("    [NonUniformReturn]\n")
21859
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21860
0
SLANG_RAW("    float4x3 ")
21861
0
SLANG_SPLICE(ccName
21862
0
)
21863
0
SLANG_SPLICE(matName
21864
0
)
21865
0
SLANG_RAW("4x3()\n")
21866
0
SLANG_RAW("    {\n")
21867
0
SLANG_RAW("        __target_switch\n")
21868
0
SLANG_RAW("        {\n")
21869
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersection")
21870
0
SLANG_SPLICE(matName
21871
0
)
21872
0
SLANG_RAW("EXT($0, ")
21873
0
SLANG_SPLICE(ccTF
21874
0
)
21875
0
SLANG_RAW(")\";\n")
21876
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".")
21877
0
SLANG_SPLICE(ccName
21878
0
)
21879
0
SLANG_SPLICE(matName
21880
0
)
21881
0
SLANG_RAW("4x3\";\n")
21882
0
SLANG_RAW("        case spirv:\n")
21883
0
SLANG_RAW("            uint iCandidateOrCommitted = ")
21884
0
SLANG_SPLICE(candidateOrCommitted
21885
0
)
21886
0
SLANG_RAW(";\n")
21887
0
SLANG_RAW("            return spirv_asm\n")
21888
0
SLANG_RAW("            {\n")
21889
0
SLANG_RAW("                result:$$float4x3 = OpRayQueryGetIntersection")
21890
0
SLANG_SPLICE(matName
21891
0
)
21892
0
SLANG_RAW("KHR &this $iCandidateOrCommitted;\n")
21893
0
SLANG_RAW("            };\n")
21894
0
SLANG_RAW("        }\n")
21895
0
SLANG_RAW("    }\n")
21896
0
SLANG_RAW("\n")
21897
21898
0
    } // ObjectToWorld/WorldToObject.
21899
21900
    // Access Candidate and Committed properties.
21901
0
    struct RayQueryMethodEntry
21902
0
    {
21903
0
        const char* type;
21904
0
        const char* hlslName;
21905
0
        const char* glslName;
21906
0
    };
21907
0
    const RayQueryMethodEntry rayQueryMethods[] = {
21908
0
        {"uint", "InstanceIndex", "InstanceId"},
21909
0
        {"uint", "InstanceID", "InstanceCustomIndex"},
21910
0
        {"uint", "PrimitiveIndex", "PrimitiveIndex"},
21911
0
        {"uint", "GeometryIndex", "GeometryIndex"},
21912
0
        {"uint", "InstanceContributionToHitGroupIndex", "InstanceShaderBindingTableRecordOffset"},
21913
0
        {"float3", "ObjectRayOrigin", "ObjectRayOrigin"},
21914
0
        {"float3", "ObjectRayDirection", "ObjectRayDirection"},
21915
0
        {"bool", "TriangleFrontFace", "FrontFace"},
21916
0
        {"float2", "TriangleBarycentrics", "Barycentrics"},
21917
0
    };
21918
0
    for (auto method : rayQueryMethods) {
21919
0
SLANG_RAW("#line 19793 \"hlsl.meta.slang\"")
21920
0
SLANG_RAW("\n")
21921
0
SLANG_RAW("\n")
21922
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21923
0
SLANG_RAW("    [__NoSideEffect]\n")
21924
0
SLANG_RAW("    [NonUniformReturn]\n")
21925
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21926
0
SLANG_RAW("    ")
21927
0
SLANG_SPLICE(method.type
21928
0
)
21929
0
SLANG_RAW(" ")
21930
0
SLANG_SPLICE(ccName
21931
0
)
21932
0
SLANG_SPLICE(method.hlslName
21933
0
)
21934
0
SLANG_RAW("()\n")
21935
0
SLANG_RAW("    {\n")
21936
0
SLANG_RAW("        __target_switch\n")
21937
0
SLANG_RAW("        {\n")
21938
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".")
21939
0
SLANG_SPLICE(ccName
21940
0
)
21941
0
SLANG_SPLICE(method.hlslName
21942
0
)
21943
0
SLANG_RAW("\";\n")
21944
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetIntersection")
21945
0
SLANG_SPLICE(method.glslName
21946
0
)
21947
0
SLANG_RAW("EXT($0, ")
21948
0
SLANG_SPLICE(ccTF
21949
0
)
21950
0
SLANG_RAW(")\";\n")
21951
0
SLANG_RAW("        case spirv:\n")
21952
0
SLANG_RAW("            uint iCandidateOrCommitted = ")
21953
0
SLANG_SPLICE(candidateOrCommitted
21954
0
)
21955
0
SLANG_RAW(";\n")
21956
0
SLANG_RAW("            return spirv_asm\n")
21957
0
SLANG_RAW("            {\n")
21958
0
SLANG_RAW("                result:$$")
21959
0
SLANG_SPLICE(method.type
21960
0
)
21961
0
SLANG_RAW(" = OpRayQueryGetIntersection")
21962
0
SLANG_SPLICE(method.glslName
21963
0
)
21964
0
SLANG_RAW("KHR &this $iCandidateOrCommitted;\n")
21965
0
SLANG_RAW("            };\n")
21966
0
SLANG_RAW("        }\n")
21967
0
SLANG_RAW("    }\n")
21968
21969
0
    } // Candidate/Committed properties.
21970
0
    } // for ("Candidate", "Committed")
21971
0
SLANG_RAW("#line 19816 \"hlsl.meta.slang\"")
21972
0
SLANG_RAW("\n")
21973
0
SLANG_RAW("\n")
21974
0
SLANG_RAW("    // Access properties of the ray being traced.\n")
21975
0
SLANG_RAW("\n")
21976
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21977
0
SLANG_RAW("    [__NoSideEffect]\n")
21978
0
SLANG_RAW("    [NonUniformReturn]\n")
21979
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
21980
0
SLANG_RAW("    uint RayFlags()\n")
21981
0
SLANG_RAW("    {\n")
21982
0
SLANG_RAW("        __target_switch\n")
21983
0
SLANG_RAW("        {\n")
21984
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".RayFlags\";\n")
21985
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetRayFlagsEXT\";\n")
21986
0
SLANG_RAW("        case spirv:\n")
21987
0
SLANG_RAW("            return spirv_asm\n")
21988
0
SLANG_RAW("            {\n")
21989
0
SLANG_RAW("                result:$$uint = OpRayQueryGetRayFlagsKHR &this;\n")
21990
0
SLANG_RAW("            };\n")
21991
0
SLANG_RAW("        }\n")
21992
0
SLANG_RAW("    }\n")
21993
0
SLANG_RAW("\n")
21994
0
SLANG_RAW("    /// Gets the world-space origin of the ray.\n")
21995
0
SLANG_RAW("    /// @return Starting point of the ray in world space\n")
21996
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
21997
0
SLANG_RAW("    [__NoSideEffect]\n")
21998
0
SLANG_RAW("    [NonUniformReturn]\n")
21999
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
22000
0
SLANG_RAW("    float3 WorldRayOrigin()\n")
22001
0
SLANG_RAW("    {\n")
22002
0
SLANG_RAW("        __target_switch\n")
22003
0
SLANG_RAW("        {\n")
22004
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".WorldRayOrigin\";\n")
22005
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetWorldRayOriginEXT\";\n")
22006
0
SLANG_RAW("        case spirv:\n")
22007
0
SLANG_RAW("            return spirv_asm\n")
22008
0
SLANG_RAW("            {\n")
22009
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetWorldRayOriginKHR &this;\n")
22010
0
SLANG_RAW("            };\n")
22011
0
SLANG_RAW("        }\n")
22012
0
SLANG_RAW("    }\n")
22013
0
SLANG_RAW("\n")
22014
0
SLANG_RAW("    /// Gets the world-space direction of the ray.\n")
22015
0
SLANG_RAW("    /// @return Normalized direction vector in world space\n")
22016
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
22017
0
SLANG_RAW("    [__NoSideEffect]\n")
22018
0
SLANG_RAW("    [NonUniformReturn]\n")
22019
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
22020
0
SLANG_RAW("    float3 WorldRayDirection()\n")
22021
0
SLANG_RAW("    {\n")
22022
0
SLANG_RAW("        __target_switch\n")
22023
0
SLANG_RAW("        {\n")
22024
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".WorldRayDirection\";\n")
22025
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetWorldRayDirectionEXT\";\n")
22026
0
SLANG_RAW("        case spirv:\n")
22027
0
SLANG_RAW("            return spirv_asm\n")
22028
0
SLANG_RAW("            {\n")
22029
0
SLANG_RAW("                result:$$float3 = OpRayQueryGetWorldRayDirectionKHR &this;\n")
22030
0
SLANG_RAW("            };\n")
22031
0
SLANG_RAW("        }\n")
22032
0
SLANG_RAW("    }\n")
22033
0
SLANG_RAW("\n")
22034
0
SLANG_RAW("    /// Gets the minimum valid distance along the ray.\n")
22035
0
SLANG_RAW("    /// @return Minimum t-value for considering intersections\n")
22036
0
SLANG_RAW("    /// @remarks Used to prevent self-intersections\n")
22037
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_query)\n")
22038
0
SLANG_RAW("    [__NoSideEffect]\n")
22039
0
SLANG_RAW("    [NonUniformReturn]\n")
22040
0
SLANG_RAW("    [require(glsl_hlsl_spirv, rayquery)]\n")
22041
0
SLANG_RAW("    float RayTMin()\n")
22042
0
SLANG_RAW("    {\n")
22043
0
SLANG_RAW("        __target_switch\n")
22044
0
SLANG_RAW("        {\n")
22045
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".RayTMin\";\n")
22046
0
SLANG_RAW("        case glsl: __intrinsic_asm \"rayQueryGetRayTMinEXT\";\n")
22047
0
SLANG_RAW("        case spirv:\n")
22048
0
SLANG_RAW("            return spirv_asm\n")
22049
0
SLANG_RAW("            {\n")
22050
0
SLANG_RAW("                result:$$float = OpRayQueryGetRayTMinKHR &this;\n")
22051
0
SLANG_RAW("            };\n")
22052
0
SLANG_RAW("        }\n")
22053
0
SLANG_RAW("    };\n")
22054
0
SLANG_RAW("}\n")
22055
0
SLANG_RAW("\n")
22056
0
SLANG_RAW("//\n")
22057
0
SLANG_RAW("// SubpassInput\n")
22058
0
SLANG_RAW("//\n")
22059
0
SLANG_RAW("\n")
22060
0
SLANG_RAW("/// @category stage_io\n")
22061
0
SLANG_RAW("__magic_type(SubpassInputType)\n")
22062
0
SLANG_RAW("__intrinsic_type(")
22063
0
SLANG_SPLICE(kIROp_SubpassInputType
22064
0
)
22065
0
SLANG_RAW(")\n")
22066
0
SLANG_RAW("[require(glsl_hlsl_spirv, subpass)]\n")
22067
0
SLANG_RAW("struct __SubpassImpl<T, let isMS:int>\n")
22068
0
SLANG_RAW("{\n")
22069
0
SLANG_RAW("}\n")
22070
0
SLANG_RAW("\n")
22071
0
SLANG_RAW("/// @category stage_io\n")
22072
0
SLANG_RAW("__generic<T = float4, let isMS:int=0>\n")
22073
0
SLANG_RAW("typealias SubpassInput = __SubpassImpl<T, isMS>;\n")
22074
0
SLANG_RAW("\n")
22075
0
SLANG_RAW("__generic<T>\n")
22076
0
SLANG_RAW("extension __SubpassImpl<T, 0>\n")
22077
0
SLANG_RAW("{\n")
22078
0
SLANG_RAW("    [ForceInline]\n")
22079
0
SLANG_RAW("    [require(glsl_hlsl_spirv, subpass)]\n")
22080
0
SLANG_RAW("    T SubpassLoad()\n")
22081
0
SLANG_RAW("    {\n")
22082
0
SLANG_RAW("        __target_switch\n")
22083
0
SLANG_RAW("        {\n")
22084
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0.SubpassLoad()\";\n")
22085
0
SLANG_RAW("        case glsl: __intrinsic_asm \"subpassLoad($0)\";\n")
22086
0
SLANG_RAW("        case spirv:\n")
22087
0
SLANG_RAW("        {\n")
22088
0
SLANG_RAW("            let zeroVec = int2(0);\n")
22089
0
SLANG_RAW("            return spirv_asm\n")
22090
0
SLANG_RAW("            {\n")
22091
0
SLANG_RAW("                OpCapability StorageImageReadWithoutFormat;\n")
22092
0
SLANG_RAW("                result:$$T = OpImageRead $this $zeroVec\n")
22093
0
SLANG_RAW("            };\n")
22094
0
SLANG_RAW("        }\n")
22095
0
SLANG_RAW("        }\n")
22096
0
SLANG_RAW("    }\n")
22097
0
SLANG_RAW("}\n")
22098
0
SLANG_RAW("\n")
22099
0
SLANG_RAW("/// @category stage_io\n")
22100
0
SLANG_RAW("__generic<T = float4, let isMS:int=1>\n")
22101
0
SLANG_RAW("typealias SubpassInputMS = __SubpassImpl<T, isMS>;\n")
22102
0
SLANG_RAW("\n")
22103
0
SLANG_RAW("__generic<T>\n")
22104
0
SLANG_RAW("extension __SubpassImpl<T, 1>\n")
22105
0
SLANG_RAW("{\n")
22106
0
SLANG_RAW("    [ForceInline]\n")
22107
0
SLANG_RAW("    [require(glsl_hlsl_spirv, subpass)]\n")
22108
0
SLANG_RAW("    T SubpassLoad(int sample)\n")
22109
0
SLANG_RAW("    {\n")
22110
0
SLANG_RAW("        __target_switch\n")
22111
0
SLANG_RAW("        {\n")
22112
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0.SubpassLoad($1)\";\n")
22113
0
SLANG_RAW("        case glsl: __intrinsic_asm \"subpassLoad($0, $1)\";\n")
22114
0
SLANG_RAW("        case spirv:\n")
22115
0
SLANG_RAW("        {\n")
22116
0
SLANG_RAW("            let zeroVec = int2(0);\n")
22117
0
SLANG_RAW("            return spirv_asm\n")
22118
0
SLANG_RAW("            {\n")
22119
0
SLANG_RAW("                OpCapability StorageImageReadWithoutFormat;\n")
22120
0
SLANG_RAW("                result:$$T = OpImageRead $this $zeroVec Sample $sample\n")
22121
0
SLANG_RAW("            };\n")
22122
0
SLANG_RAW("        }\n")
22123
0
SLANG_RAW("        }\n")
22124
0
SLANG_RAW("    }\n")
22125
0
SLANG_RAW("}\n")
22126
0
SLANG_RAW("\n")
22127
0
SLANG_RAW("///\n")
22128
0
SLANG_RAW("/// Shader Execution Reordering (SER)\n")
22129
0
SLANG_RAW("///\n")
22130
0
SLANG_RAW("/// NOTE! This API is currently experimental and may change in the future as SER is made available\n")
22131
0
SLANG_RAW("/// in different APIs and downstream compilers.\n")
22132
0
SLANG_RAW("///\n")
22133
0
SLANG_RAW("/// Based on the NVAPI on D3D12 only currently.\n")
22134
0
SLANG_RAW("///\n")
22135
0
SLANG_RAW("/// White paper on SER on NVAPI https://developer.nvidia.com/sites/default/files/akamai/gameworks/ser-whitepaper.pdf\n")
22136
0
SLANG_RAW("///\n")
22137
0
SLANG_RAW("/// The NVAPI headers (R520) required for this functionality to work can be found here...\n")
22138
0
SLANG_RAW("///\n")
22139
0
SLANG_RAW("/// https://developer.nvidia.com/rtx/path-tracing/nvapi/get-started\n")
22140
0
SLANG_RAW("///\n")
22141
0
SLANG_RAW("/// For VK the specification is currently in this PR\n")
22142
0
SLANG_RAW("///\n")
22143
0
SLANG_RAW("/// https://github.com/KhronosGroup/GLSL/pull/196/files\n")
22144
0
SLANG_RAW("\n")
22145
0
SLANG_RAW("/// Internal helper functions\n")
22146
0
SLANG_RAW("\n")
22147
0
SLANG_RAW("// This is a bit of a hack for GLSL HitObjectAttributes\n")
22148
0
SLANG_RAW("// It relies on [ForceInline] removing the surrounding function and just inserting the *contained* `t` as a global\n")
22149
0
SLANG_RAW("// The __ref should indicate the desire for the returned value to not be a copy of t, but *t*.\n")
22150
0
SLANG_RAW("// In practive __ref doesn't have this effect in practice.\n")
22151
0
SLANG_RAW("//\n")
22152
0
SLANG_RAW("// We need this to be able access the payload outside of a function (which is all that TraceRay for example needs)\n")
22153
0
SLANG_RAW("// We access the HitObjectAttributes via this function for the desired type, and it acts *as if* it's just an access\n")
22154
0
SLANG_RAW("// to the global t.\n")
22155
0
SLANG_RAW("[ForceInline]\n")
22156
0
SLANG_RAW("Ref<T> __hitObjectAttributes<T>()\n")
22157
0
SLANG_RAW("{\n")
22158
0
SLANG_RAW("    [__vulkanHitObjectAttributes]\n")
22159
0
SLANG_RAW("    static T t;\n")
22160
0
SLANG_RAW("    return t;\n")
22161
0
SLANG_RAW("}\n")
22162
0
SLANG_RAW("[ForceInline]\n")
22163
0
SLANG_RAW("__Addr<T> __allocHitObjectAttributes<T>()\n")
22164
0
SLANG_RAW("{\n")
22165
0
SLANG_RAW("    [__vulkanHitObjectAttributes]\n")
22166
0
SLANG_RAW("    static T t;\n")
22167
0
SLANG_RAW("    return __getAddress(t);\n")
22168
0
SLANG_RAW("}\n")
22169
0
SLANG_RAW("\n")
22170
0
SLANG_RAW("// Next is the custom intrinsic that will compute the hitObjectAttributes location\n")
22171
0
SLANG_RAW("// for GLSL-based targets.\n")
22172
0
SLANG_RAW("//\n")
22173
0
SLANG_RAW("__generic<Attributes>\n")
22174
0
SLANG_RAW("__intrinsic_op(")
22175
0
SLANG_SPLICE(kIROp_GetVulkanRayTracingPayloadLocation
22176
0
)
22177
0
SLANG_RAW(")\n")
22178
0
SLANG_RAW("int __hitObjectAttributesLocation(__ref Attributes attributes);\n")
22179
0
SLANG_RAW("\n")
22180
0
SLANG_RAW("/// Immutable data type representing a ray hit or a miss. Can be used to invoke hit or miss shading,\n")
22181
0
SLANG_RAW("/// or as a key in ReorderThread. Created by one of several methods described below. HitObject\n")
22182
0
SLANG_RAW("/// and its related functions are available in raytracing shader types only.\n")
22183
0
SLANG_RAW("/// @category raytracing Ray-tracing\n")
22184
0
SLANG_RAW("__glsl_extension(GL_NV_shader_invocation_reorder)\n")
22185
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
22186
0
SLANG_RAW("[__NonCopyableType]\n")
22187
0
SLANG_RAW("__intrinsic_type(")
22188
0
SLANG_SPLICE(kIROp_HitObjectType
22189
0
)
22190
0
SLANG_RAW(")\n")
22191
0
SLANG_RAW("struct HitObject\n")
22192
0
SLANG_RAW("{\n")
22193
0
SLANG_RAW("    __intrinsic_op(")
22194
0
SLANG_SPLICE(kIROp_AllocateOpaqueHandle
22195
0
)
22196
0
SLANG_RAW(")\n")
22197
0
SLANG_RAW("    __init();\n")
22198
0
SLANG_RAW("\n")
22199
0
SLANG_RAW("        /// Executes ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the\n")
22200
0
SLANG_RAW("        /// resulting hit information as a HitObject and does not trigger closesthit or miss shaders.\n")
22201
0
SLANG_RAW("    [ForceInline]\n")
22202
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22203
0
SLANG_RAW("    static HitObject TraceRay<payload_t>(\n")
22204
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22205
0
SLANG_RAW("        uint RayFlags,\n")
22206
0
SLANG_RAW("        uint InstanceInclusionMask,\n")
22207
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
22208
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
22209
0
SLANG_RAW("        uint MissShaderIndex,\n")
22210
0
SLANG_RAW("        RayDesc Ray,\n")
22211
0
SLANG_RAW("        inout payload_t Payload)\n")
22212
0
SLANG_RAW("    {\n")
22213
0
SLANG_RAW("        __target_switch\n")
22214
0
SLANG_RAW("        {\n")
22215
0
SLANG_RAW("        case hlsl:\n")
22216
0
SLANG_RAW("            {\n")
22217
0
SLANG_RAW("                HitObject hitObj;\n")
22218
0
SLANG_RAW("                __hlslTraceRay(\n")
22219
0
SLANG_RAW("                    AccelerationStructure,\n")
22220
0
SLANG_RAW("                    RayFlags,\n")
22221
0
SLANG_RAW("                    InstanceInclusionMask,\n")
22222
0
SLANG_RAW("                    RayContributionToHitGroupIndex,\n")
22223
0
SLANG_RAW("                    MultiplierForGeometryContributionToHitGroupIndex,\n")
22224
0
SLANG_RAW("                    MissShaderIndex,\n")
22225
0
SLANG_RAW("                    Ray,\n")
22226
0
SLANG_RAW("                    __forceVarIntoRayPayloadStructTemporarily(Payload),\n")
22227
0
SLANG_RAW("                    hitObj);\n")
22228
0
SLANG_RAW("                return hitObj;\n")
22229
0
SLANG_RAW("            }\n")
22230
0
SLANG_RAW("        case glsl:\n")
22231
0
SLANG_RAW("            {\n")
22232
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22233
0
SLANG_RAW("                static payload_t p;\n")
22234
0
SLANG_RAW("\n")
22235
0
SLANG_RAW("                // Save the payload\n")
22236
0
SLANG_RAW("                p = Payload;\n")
22237
0
SLANG_RAW("\n")
22238
0
SLANG_RAW("                __glslTraceRay(\n")
22239
0
SLANG_RAW("                    __return_val,\n")
22240
0
SLANG_RAW("                    AccelerationStructure,\n")
22241
0
SLANG_RAW("                    RayFlags,                                           // Assumes D3D/VK have some RayFlags values\n")
22242
0
SLANG_RAW("                    InstanceInclusionMask,                              // cullMask\n")
22243
0
SLANG_RAW("                    RayContributionToHitGroupIndex,                     // sbtRecordOffset\n")
22244
0
SLANG_RAW("                    MultiplierForGeometryContributionToHitGroupIndex,   // sbtRecordStride\n")
22245
0
SLANG_RAW("                    MissShaderIndex,\n")
22246
0
SLANG_RAW("                    Ray.Origin,\n")
22247
0
SLANG_RAW("                    Ray.TMin,\n")
22248
0
SLANG_RAW("                    Ray.Direction,\n")
22249
0
SLANG_RAW("                    Ray.TMax,\n")
22250
0
SLANG_RAW("                    __rayPayloadLocation(p));\n")
22251
0
SLANG_RAW("\n")
22252
0
SLANG_RAW("                // Write the payload out\n")
22253
0
SLANG_RAW("                Payload = p;\n")
22254
0
SLANG_RAW("            }\n")
22255
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixTraverse\";\n")
22256
0
SLANG_RAW("        case spirv:\n")
22257
0
SLANG_RAW("            {\n")
22258
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22259
0
SLANG_RAW("                static payload_t p;\n")
22260
0
SLANG_RAW("\n")
22261
0
SLANG_RAW("                // Save the payload\n")
22262
0
SLANG_RAW("                p = Payload;\n")
22263
0
SLANG_RAW("\n")
22264
0
SLANG_RAW("                let origin = Ray.Origin;\n")
22265
0
SLANG_RAW("                let direction = Ray.Direction;\n")
22266
0
SLANG_RAW("                let tmin = Ray.TMin;\n")
22267
0
SLANG_RAW("                let tmax = Ray.TMax;\n")
22268
0
SLANG_RAW("                spirv_asm\n")
22269
0
SLANG_RAW("                {\n")
22270
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22271
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
22272
0
SLANG_RAW("                    OpHitObjectTraceRayNV\n")
22273
0
SLANG_RAW("                        /**/ &__return_val\n")
22274
0
SLANG_RAW("                        /**/ $AccelerationStructure\n")
22275
0
SLANG_RAW("                        /**/ $RayFlags\n")
22276
0
SLANG_RAW("                        /**/ $InstanceInclusionMask\n")
22277
0
SLANG_RAW("                        /**/ $RayContributionToHitGroupIndex\n")
22278
0
SLANG_RAW("                        /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
22279
0
SLANG_RAW("                        /**/ $MissShaderIndex\n")
22280
0
SLANG_RAW("                        /**/ $origin\n")
22281
0
SLANG_RAW("                        /**/ $tmin\n")
22282
0
SLANG_RAW("                        /**/ $direction\n")
22283
0
SLANG_RAW("                        /**/ $tmax\n")
22284
0
SLANG_RAW("                        /**/ &p;\n")
22285
0
SLANG_RAW("                };\n")
22286
0
SLANG_RAW("\n")
22287
0
SLANG_RAW("                // Write the payload out\n")
22288
0
SLANG_RAW("                Payload = p;\n")
22289
0
SLANG_RAW("            }\n")
22290
0
SLANG_RAW("        }\n")
22291
0
SLANG_RAW("    }\n")
22292
0
SLANG_RAW("\n")
22293
0
SLANG_RAW("        /// Executes motion ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the\n")
22294
0
SLANG_RAW("        /// resulting hit information as a HitObject and does not trigger closesthit or miss shaders.\n")
22295
0
SLANG_RAW("    [ForceInline]\n")
22296
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_motion_raygen_closesthit_miss)]\n")
22297
0
SLANG_RAW("    static HitObject TraceMotionRay<payload_t>(\n")
22298
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22299
0
SLANG_RAW("        uint RayFlags,\n")
22300
0
SLANG_RAW("        uint InstanceInclusionMask,\n")
22301
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
22302
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
22303
0
SLANG_RAW("        uint MissShaderIndex,\n")
22304
0
SLANG_RAW("        RayDesc Ray,\n")
22305
0
SLANG_RAW("        float CurrentTime,\n")
22306
0
SLANG_RAW("        inout payload_t Payload)\n")
22307
0
SLANG_RAW("    {\n")
22308
0
SLANG_RAW("        __target_switch\n")
22309
0
SLANG_RAW("        {\n")
22310
0
SLANG_RAW("        case hlsl:\n")
22311
0
SLANG_RAW("            __traceMotionRayHLSL(\n")
22312
0
SLANG_RAW("                AccelerationStructure,\n")
22313
0
SLANG_RAW("                RayFlags,\n")
22314
0
SLANG_RAW("                InstanceInclusionMask,\n")
22315
0
SLANG_RAW("                RayContributionToHitGroupIndex,\n")
22316
0
SLANG_RAW("                MultiplierForGeometryContributionToHitGroupIndex,\n")
22317
0
SLANG_RAW("                MissShaderIndex,\n")
22318
0
SLANG_RAW("                Ray,\n")
22319
0
SLANG_RAW("                CurrentTime,\n")
22320
0
SLANG_RAW("                __forceVarIntoRayPayloadStructTemporarily(Payload));\n")
22321
0
SLANG_RAW("        case glsl:\n")
22322
0
SLANG_RAW("            {\n")
22323
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22324
0
SLANG_RAW("                static payload_t p;\n")
22325
0
SLANG_RAW("\n")
22326
0
SLANG_RAW("                // Save the payload\n")
22327
0
SLANG_RAW("                p = Payload;\n")
22328
0
SLANG_RAW("\n")
22329
0
SLANG_RAW("                __glslTraceMotionRay(\n")
22330
0
SLANG_RAW("                    __return_val,\n")
22331
0
SLANG_RAW("                    AccelerationStructure,\n")
22332
0
SLANG_RAW("                    RayFlags,                                           // Assumes D3D/VK have some RayFlags values\n")
22333
0
SLANG_RAW("                    InstanceInclusionMask,                              // cullMask\n")
22334
0
SLANG_RAW("                    RayContributionToHitGroupIndex,                     // sbtRecordOffset\n")
22335
0
SLANG_RAW("                    MultiplierForGeometryContributionToHitGroupIndex,   // sbtRecordStride\n")
22336
0
SLANG_RAW("                    MissShaderIndex,\n")
22337
0
SLANG_RAW("                    Ray.Origin,\n")
22338
0
SLANG_RAW("                    Ray.TMin,\n")
22339
0
SLANG_RAW("                    Ray.Direction,\n")
22340
0
SLANG_RAW("                    Ray.TMax,\n")
22341
0
SLANG_RAW("                    CurrentTime,\n")
22342
0
SLANG_RAW("                    __rayPayloadLocation(p));\n")
22343
0
SLANG_RAW("\n")
22344
0
SLANG_RAW("                // Write the payload out\n")
22345
0
SLANG_RAW("                Payload = p;\n")
22346
0
SLANG_RAW("            }\n")
22347
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixTraverse\";\n")
22348
0
SLANG_RAW("        case spirv:\n")
22349
0
SLANG_RAW("            {\n")
22350
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22351
0
SLANG_RAW("                static payload_t p;\n")
22352
0
SLANG_RAW("\n")
22353
0
SLANG_RAW("                // Save the payload\n")
22354
0
SLANG_RAW("                p = Payload;\n")
22355
0
SLANG_RAW("\n")
22356
0
SLANG_RAW("                let origin = Ray.Origin;\n")
22357
0
SLANG_RAW("                let direction = Ray.Direction;\n")
22358
0
SLANG_RAW("                let tmin = Ray.TMin;\n")
22359
0
SLANG_RAW("                let tmax = Ray.TMax;\n")
22360
0
SLANG_RAW("                spirv_asm\n")
22361
0
SLANG_RAW("                {\n")
22362
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22363
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
22364
0
SLANG_RAW("                    OpExtension \"SPV_NV_ray_tracing_motion_blur\";\n")
22365
0
SLANG_RAW("                    OpCapability RayTracingMotionBlurNV;\n")
22366
0
SLANG_RAW("                    OpHitObjectTraceRayMotionNV\n")
22367
0
SLANG_RAW("                        /**/ &__return_val\n")
22368
0
SLANG_RAW("                        /**/ $AccelerationStructure\n")
22369
0
SLANG_RAW("                        /**/ $RayFlags\n")
22370
0
SLANG_RAW("                        /**/ $InstanceInclusionMask\n")
22371
0
SLANG_RAW("                        /**/ $RayContributionToHitGroupIndex\n")
22372
0
SLANG_RAW("                        /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
22373
0
SLANG_RAW("                        /**/ $MissShaderIndex\n")
22374
0
SLANG_RAW("                        /**/ $origin\n")
22375
0
SLANG_RAW("                        /**/ $tmin\n")
22376
0
SLANG_RAW("                        /**/ $direction\n")
22377
0
SLANG_RAW("                        /**/ $tmax\n")
22378
0
SLANG_RAW("                        /**/ $CurrentTime\n")
22379
0
SLANG_RAW("                        /**/ &p;\n")
22380
0
SLANG_RAW("                };\n")
22381
0
SLANG_RAW("\n")
22382
0
SLANG_RAW("                // Write the payload out\n")
22383
0
SLANG_RAW("                Payload = p;\n")
22384
0
SLANG_RAW("            }\n")
22385
0
SLANG_RAW("        }\n")
22386
0
SLANG_RAW("\n")
22387
0
SLANG_RAW("    }\n")
22388
0
SLANG_RAW("\n")
22389
0
SLANG_RAW("        /// Creates a HitObject representing a hit based on values explicitly passed as arguments, without\n")
22390
0
SLANG_RAW("        /// tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex,\n")
22391
0
SLANG_RAW("        /// and PrimitiveIndex must exist. The shader table index is computed using the formula used with\n")
22392
0
SLANG_RAW("        /// TraceRay. The computed index must reference a valid hit group record in the shader table. The\n")
22393
0
SLANG_RAW("        /// Attributes parameter must either be an attribute struct, such as\n")
22394
0
SLANG_RAW("        /// BuiltInTriangleIntersectionAttributes, or another HitObject to copy the attributes from.\n")
22395
0
SLANG_RAW("    [ForceInline]\n")
22396
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22397
0
SLANG_RAW("    static HitObject MakeHit<attr_t>(\n")
22398
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22399
0
SLANG_RAW("        uint InstanceIndex,\n")
22400
0
SLANG_RAW("        uint GeometryIndex,\n")
22401
0
SLANG_RAW("        uint PrimitiveIndex,\n")
22402
0
SLANG_RAW("        uint HitKind,\n")
22403
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
22404
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
22405
0
SLANG_RAW("        RayDesc Ray,\n")
22406
0
SLANG_RAW("        attr_t attributes)\n")
22407
0
SLANG_RAW("    {\n")
22408
0
SLANG_RAW("        __target_switch\n")
22409
0
SLANG_RAW("        {\n")
22410
0
SLANG_RAW("        case hlsl:\n")
22411
0
SLANG_RAW("            HitObject hitObj;\n")
22412
0
SLANG_RAW("            __hlslMakeHit(\n")
22413
0
SLANG_RAW("                AccelerationStructure,\n")
22414
0
SLANG_RAW("                InstanceIndex,\n")
22415
0
SLANG_RAW("                GeometryIndex,\n")
22416
0
SLANG_RAW("                PrimitiveIndex,\n")
22417
0
SLANG_RAW("                HitKind,\n")
22418
0
SLANG_RAW("                RayContributionToHitGroupIndex,\n")
22419
0
SLANG_RAW("                MultiplierForGeometryContributionToHitGroupIndex,\n")
22420
0
SLANG_RAW("                Ray,\n")
22421
0
SLANG_RAW("                attributes,\n")
22422
0
SLANG_RAW("                hitObj);\n")
22423
0
SLANG_RAW("            return hitObj;\n")
22424
0
SLANG_RAW("        case glsl:\n")
22425
0
SLANG_RAW("            {\n")
22426
0
SLANG_RAW("                // Save the attributes\n")
22427
0
SLANG_RAW("                __hitObjectAttributes<attr_t>() = attributes;\n")
22428
0
SLANG_RAW("\n")
22429
0
SLANG_RAW("                __glslMakeHit(\n")
22430
0
SLANG_RAW("                    __return_val,\n")
22431
0
SLANG_RAW("                    AccelerationStructure,\n")
22432
0
SLANG_RAW("                    InstanceIndex,\n")
22433
0
SLANG_RAW("                    PrimitiveIndex,\n")
22434
0
SLANG_RAW("                    GeometryIndex,\n")
22435
0
SLANG_RAW("                    HitKind,\n")
22436
0
SLANG_RAW("                    RayContributionToHitGroupIndex,                         /// sbtRecordOffset?\n")
22437
0
SLANG_RAW("                    MultiplierForGeometryContributionToHitGroupIndex,       /// sbtRecordStride?\n")
22438
0
SLANG_RAW("                    Ray.Origin,\n")
22439
0
SLANG_RAW("                    Ray.TMin,\n")
22440
0
SLANG_RAW("                    Ray.Direction,\n")
22441
0
SLANG_RAW("                    Ray.TMax,\n")
22442
0
SLANG_RAW("                    __hitObjectAttributesLocation(__hitObjectAttributes<attr_t>()));\n")
22443
0
SLANG_RAW("            }\n")
22444
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeHitObject\";\n")
22445
0
SLANG_RAW("        case spirv:\n")
22446
0
SLANG_RAW("            {\n")
22447
0
SLANG_RAW("                // Save the attributes\n")
22448
0
SLANG_RAW("                __Addr<attr_t> attr = __allocHitObjectAttributes<attr_t>();\n")
22449
0
SLANG_RAW("\n")
22450
0
SLANG_RAW("                *attr = attributes;\n")
22451
0
SLANG_RAW("\n")
22452
0
SLANG_RAW("                let origin = Ray.Origin;\n")
22453
0
SLANG_RAW("                let direction = Ray.Direction;\n")
22454
0
SLANG_RAW("                let tmin = Ray.TMin;\n")
22455
0
SLANG_RAW("                let tmax = Ray.TMax;\n")
22456
0
SLANG_RAW("                spirv_asm\n")
22457
0
SLANG_RAW("                {\n")
22458
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22459
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
22460
0
SLANG_RAW("                    OpHitObjectRecordHitNV\n")
22461
0
SLANG_RAW("                        /**/ &__return_val\n")
22462
0
SLANG_RAW("                        /**/ $AccelerationStructure\n")
22463
0
SLANG_RAW("                        /**/ $InstanceIndex\n")
22464
0
SLANG_RAW("                        /**/ $PrimitiveIndex\n")
22465
0
SLANG_RAW("                        /**/ $GeometryIndex\n")
22466
0
SLANG_RAW("                        /**/ $HitKind\n")
22467
0
SLANG_RAW("                        /**/ $RayContributionToHitGroupIndex\n")
22468
0
SLANG_RAW("                        /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
22469
0
SLANG_RAW("                        /**/ $origin\n")
22470
0
SLANG_RAW("                        /**/ $tmin\n")
22471
0
SLANG_RAW("                        /**/ $direction\n")
22472
0
SLANG_RAW("                        /**/ $tmax\n")
22473
0
SLANG_RAW("                        /**/ $attr;\n")
22474
0
SLANG_RAW("                };\n")
22475
0
SLANG_RAW("            }\n")
22476
0
SLANG_RAW("        }\n")
22477
0
SLANG_RAW("    }\n")
22478
0
SLANG_RAW("\n")
22479
0
SLANG_RAW("        /// See MakeHit but handles Motion\n")
22480
0
SLANG_RAW("        /// Currently only supported on VK\n")
22481
0
SLANG_RAW("    [ForceInline]\n")
22482
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_motion_raygen_closesthit_miss)]\n")
22483
0
SLANG_RAW("    static HitObject MakeMotionHit<attr_t>(\n")
22484
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22485
0
SLANG_RAW("        uint InstanceIndex,\n")
22486
0
SLANG_RAW("        uint GeometryIndex,\n")
22487
0
SLANG_RAW("        uint PrimitiveIndex,\n")
22488
0
SLANG_RAW("        uint HitKind,\n")
22489
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
22490
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
22491
0
SLANG_RAW("        RayDesc Ray,\n")
22492
0
SLANG_RAW("        float CurrentTime,\n")
22493
0
SLANG_RAW("        attr_t attributes)\n")
22494
0
SLANG_RAW("    {\n")
22495
0
SLANG_RAW("        __target_switch\n")
22496
0
SLANG_RAW("        {\n")
22497
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"MakeMotionHit\";\n")
22498
0
SLANG_RAW("        case glsl:\n")
22499
0
SLANG_RAW("        {\n")
22500
0
SLANG_RAW("            // Save the attributes\n")
22501
0
SLANG_RAW("            __hitObjectAttributes<attr_t>() = attributes;\n")
22502
0
SLANG_RAW("\n")
22503
0
SLANG_RAW("            __glslMakeMotionHit(\n")
22504
0
SLANG_RAW("                __return_val,\n")
22505
0
SLANG_RAW("                AccelerationStructure,\n")
22506
0
SLANG_RAW("                InstanceIndex,\n")
22507
0
SLANG_RAW("                PrimitiveIndex,\n")
22508
0
SLANG_RAW("                GeometryIndex,\n")
22509
0
SLANG_RAW("                HitKind,\n")
22510
0
SLANG_RAW("                RayContributionToHitGroupIndex,                         /// sbtRecordOffset?\n")
22511
0
SLANG_RAW("                MultiplierForGeometryContributionToHitGroupIndex,       /// sbtRecordStride?\n")
22512
0
SLANG_RAW("                Ray.Origin,\n")
22513
0
SLANG_RAW("                Ray.TMin,\n")
22514
0
SLANG_RAW("                Ray.Direction,\n")
22515
0
SLANG_RAW("                Ray.TMax,\n")
22516
0
SLANG_RAW("                CurrentTime,\n")
22517
0
SLANG_RAW("                __hitObjectAttributesLocation(__hitObjectAttributes<attr_t>()));\n")
22518
0
SLANG_RAW("        }\n")
22519
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeHitObject\";\n")
22520
0
SLANG_RAW("        case spirv:\n")
22521
0
SLANG_RAW("        {\n")
22522
0
SLANG_RAW("            // Save the attributes\n")
22523
0
SLANG_RAW("            __Addr<attr_t> attr = __allocHitObjectAttributes<attr_t>();\n")
22524
0
SLANG_RAW("\n")
22525
0
SLANG_RAW("            *attr = attributes;\n")
22526
0
SLANG_RAW("\n")
22527
0
SLANG_RAW("            let origin = Ray.Origin;\n")
22528
0
SLANG_RAW("            let direction = Ray.Direction;\n")
22529
0
SLANG_RAW("            let tmin = Ray.TMin;\n")
22530
0
SLANG_RAW("            let tmax = Ray.TMax;\n")
22531
0
SLANG_RAW("            spirv_asm\n")
22532
0
SLANG_RAW("            {\n")
22533
0
SLANG_RAW("                OpExtension \"SPV_NV_ray_tracing_motion_blur\";\n")
22534
0
SLANG_RAW("                OpCapability RayTracingMotionBlurNV;\n")
22535
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22536
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22537
0
SLANG_RAW("                OpHitObjectRecordHitMotionNV\n")
22538
0
SLANG_RAW("                    /**/ &__return_val\n")
22539
0
SLANG_RAW("                    /**/ $AccelerationStructure\n")
22540
0
SLANG_RAW("                    /**/ $InstanceIndex\n")
22541
0
SLANG_RAW("                    /**/ $PrimitiveIndex\n")
22542
0
SLANG_RAW("                    /**/ $GeometryIndex\n")
22543
0
SLANG_RAW("                    /**/ $HitKind\n")
22544
0
SLANG_RAW("                    /**/ $RayContributionToHitGroupIndex\n")
22545
0
SLANG_RAW("                    /**/ $MultiplierForGeometryContributionToHitGroupIndex\n")
22546
0
SLANG_RAW("                    /**/ $origin\n")
22547
0
SLANG_RAW("                    /**/ $tmin\n")
22548
0
SLANG_RAW("                    /**/ $direction\n")
22549
0
SLANG_RAW("                    /**/ $tmax\n")
22550
0
SLANG_RAW("                    /**/ $CurrentTime\n")
22551
0
SLANG_RAW("                    /**/ $attr;\n")
22552
0
SLANG_RAW("            };\n")
22553
0
SLANG_RAW("        }\n")
22554
0
SLANG_RAW("        }\n")
22555
0
SLANG_RAW("    }\n")
22556
0
SLANG_RAW("\n")
22557
0
SLANG_RAW("        /// Creates a HitObject representing a hit based on values explicitly passed as arguments, without\n")
22558
0
SLANG_RAW("        /// tracing a ray. The primitive specified by AccelerationStructure, InstanceIndex, GeometryIndex,\n")
22559
0
SLANG_RAW("        /// and PrimitiveIndex must exist. The shader table index is explicitly provided as an argument\n")
22560
0
SLANG_RAW("        /// instead of being computed from the indexing formula used in TraceRay. The provided index must\n")
22561
0
SLANG_RAW("        /// reference a valid hit group record in the shader table. The Attributes parameter must either be an\n")
22562
0
SLANG_RAW("        /// attribute struct, such as BuiltInTriangleIntersectionAttributes, or another HitObject to copy the\n")
22563
0
SLANG_RAW("        /// attributes from.\n")
22564
0
SLANG_RAW("    [ForceInline]\n")
22565
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22566
0
SLANG_RAW("    static HitObject MakeHit<attr_t>(\n")
22567
0
SLANG_RAW("        uint HitGroupRecordIndex,\n")
22568
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22569
0
SLANG_RAW("        uint InstanceIndex,\n")
22570
0
SLANG_RAW("        uint GeometryIndex,\n")
22571
0
SLANG_RAW("        uint PrimitiveIndex,\n")
22572
0
SLANG_RAW("        uint HitKind,\n")
22573
0
SLANG_RAW("        RayDesc Ray,\n")
22574
0
SLANG_RAW("        attr_t attributes)\n")
22575
0
SLANG_RAW("    {\n")
22576
0
SLANG_RAW("        __target_switch\n")
22577
0
SLANG_RAW("        {\n")
22578
0
SLANG_RAW("        case hlsl:\n")
22579
0
SLANG_RAW("            HitObject hitObj;\n")
22580
0
SLANG_RAW("            __hlslMakeHitWithRecordIndex(\n")
22581
0
SLANG_RAW("                HitGroupRecordIndex,\n")
22582
0
SLANG_RAW("                AccelerationStructure,\n")
22583
0
SLANG_RAW("                InstanceIndex,\n")
22584
0
SLANG_RAW("                GeometryIndex,\n")
22585
0
SLANG_RAW("                PrimitiveIndex,\n")
22586
0
SLANG_RAW("                HitKind,\n")
22587
0
SLANG_RAW("                Ray,\n")
22588
0
SLANG_RAW("                attributes,\n")
22589
0
SLANG_RAW("                hitObj);\n")
22590
0
SLANG_RAW("            return hitObj;\n")
22591
0
SLANG_RAW("        case glsl:\n")
22592
0
SLANG_RAW("        {\n")
22593
0
SLANG_RAW("            // Save the attributes\n")
22594
0
SLANG_RAW("            __hitObjectAttributes<attr_t>() = attributes;\n")
22595
0
SLANG_RAW("\n")
22596
0
SLANG_RAW("            __glslMakeHitWithIndex(\n")
22597
0
SLANG_RAW("                __return_val,\n")
22598
0
SLANG_RAW("                AccelerationStructure,\n")
22599
0
SLANG_RAW("                InstanceIndex,              ///? Same as instanceid ?\n")
22600
0
SLANG_RAW("                PrimitiveIndex,\n")
22601
0
SLANG_RAW("                GeometryIndex,\n")
22602
0
SLANG_RAW("                HitKind,                    /// Assuming HitKinds are compatible\n")
22603
0
SLANG_RAW("                HitGroupRecordIndex,        /// sbtRecordIndex\n")
22604
0
SLANG_RAW("                Ray.Origin,\n")
22605
0
SLANG_RAW("                Ray.TMin,\n")
22606
0
SLANG_RAW("                Ray.Direction,\n")
22607
0
SLANG_RAW("                Ray.TMax,\n")
22608
0
SLANG_RAW("                __hitObjectAttributesLocation(__hitObjectAttributes<attr_t>()));\n")
22609
0
SLANG_RAW("        }\n")
22610
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeHitObject\";\n")
22611
0
SLANG_RAW("        case spirv:\n")
22612
0
SLANG_RAW("        {\n")
22613
0
SLANG_RAW("            // Save the attributes\n")
22614
0
SLANG_RAW("            __Addr<attr_t> attr = __allocHitObjectAttributes<attr_t>();\n")
22615
0
SLANG_RAW("            *attr = attributes;\n")
22616
0
SLANG_RAW("            let origin = Ray.Origin;\n")
22617
0
SLANG_RAW("            let direction = Ray.Direction;\n")
22618
0
SLANG_RAW("            let tmin = Ray.TMin;\n")
22619
0
SLANG_RAW("            let tmax = Ray.TMax;\n")
22620
0
SLANG_RAW("            spirv_asm\n")
22621
0
SLANG_RAW("            {\n")
22622
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22623
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22624
0
SLANG_RAW("                OpHitObjectRecordHitWithIndexNV\n")
22625
0
SLANG_RAW("                    /**/ &__return_val\n")
22626
0
SLANG_RAW("                    /**/ $AccelerationStructure\n")
22627
0
SLANG_RAW("                    /**/ $InstanceIndex\n")
22628
0
SLANG_RAW("                    /**/ $PrimitiveIndex\n")
22629
0
SLANG_RAW("                    /**/ $GeometryIndex\n")
22630
0
SLANG_RAW("                    /**/ $HitKind\n")
22631
0
SLANG_RAW("                    /**/ $HitGroupRecordIndex\n")
22632
0
SLANG_RAW("                    /**/ $origin\n")
22633
0
SLANG_RAW("                    /**/ $tmin\n")
22634
0
SLANG_RAW("                    /**/ $direction\n")
22635
0
SLANG_RAW("                    /**/ $tmax\n")
22636
0
SLANG_RAW("                    /**/ $attr;\n")
22637
0
SLANG_RAW("            };\n")
22638
0
SLANG_RAW("        }\n")
22639
0
SLANG_RAW("        }\n")
22640
0
SLANG_RAW("    }\n")
22641
0
SLANG_RAW("        /// See MakeHit but handles Motion\n")
22642
0
SLANG_RAW("        /// Currently only supported on VK\n")
22643
0
SLANG_RAW("    [ForceInline]\n")
22644
0
SLANG_RAW("    [require(cuda_glsl_spirv, ser_motion_raygen_closesthit_miss)]\n")
22645
0
SLANG_RAW("    static HitObject MakeMotionHit<attr_t>(\n")
22646
0
SLANG_RAW("        uint HitGroupRecordIndex,\n")
22647
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22648
0
SLANG_RAW("        uint InstanceIndex,\n")
22649
0
SLANG_RAW("        uint GeometryIndex,\n")
22650
0
SLANG_RAW("        uint PrimitiveIndex,\n")
22651
0
SLANG_RAW("        uint HitKind,\n")
22652
0
SLANG_RAW("        RayDesc Ray,\n")
22653
0
SLANG_RAW("        float CurrentTime,\n")
22654
0
SLANG_RAW("        attr_t attributes)\n")
22655
0
SLANG_RAW("    {\n")
22656
0
SLANG_RAW("        __target_switch\n")
22657
0
SLANG_RAW("        {\n")
22658
0
SLANG_RAW("        case glsl:\n")
22659
0
SLANG_RAW("        {\n")
22660
0
SLANG_RAW("            // Save the attributes\n")
22661
0
SLANG_RAW("            __hitObjectAttributes<attr_t>() = attributes;\n")
22662
0
SLANG_RAW("\n")
22663
0
SLANG_RAW("            __glslMakeMotionHitWithIndex(\n")
22664
0
SLANG_RAW("                __return_val,\n")
22665
0
SLANG_RAW("                AccelerationStructure,\n")
22666
0
SLANG_RAW("                InstanceIndex,              ///? Same as instanceid ?\n")
22667
0
SLANG_RAW("                PrimitiveIndex,\n")
22668
0
SLANG_RAW("                GeometryIndex,\n")
22669
0
SLANG_RAW("                HitKind,                    /// Assuming HitKinds are compatible\n")
22670
0
SLANG_RAW("                HitGroupRecordIndex,        /// sbtRecordIndex\n")
22671
0
SLANG_RAW("                Ray.Origin,\n")
22672
0
SLANG_RAW("                Ray.TMin,\n")
22673
0
SLANG_RAW("                Ray.Direction,\n")
22674
0
SLANG_RAW("                Ray.TMax,\n")
22675
0
SLANG_RAW("                CurrentTime,\n")
22676
0
SLANG_RAW("                __hitObjectAttributesLocation(__hitObjectAttributes<attr_t>()));\n")
22677
0
SLANG_RAW("        }\n")
22678
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeHitObject\";\n")
22679
0
SLANG_RAW("        case spirv:\n")
22680
0
SLANG_RAW("        {\n")
22681
0
SLANG_RAW("            // Save the attributes\n")
22682
0
SLANG_RAW("            __Addr<attr_t> attr = __allocHitObjectAttributes<attr_t>();\n")
22683
0
SLANG_RAW("            *attr = attributes;\n")
22684
0
SLANG_RAW("            let origin = Ray.Origin;\n")
22685
0
SLANG_RAW("            let direction = Ray.Direction;\n")
22686
0
SLANG_RAW("            let tmin = Ray.TMin;\n")
22687
0
SLANG_RAW("            let tmax = Ray.TMax;\n")
22688
0
SLANG_RAW("            spirv_asm\n")
22689
0
SLANG_RAW("            {\n")
22690
0
SLANG_RAW("                OpExtension \"SPV_NV_ray_tracing_motion_blur\";\n")
22691
0
SLANG_RAW("                OpCapability RayTracingMotionBlurNV;\n")
22692
0
SLANG_RAW("                OpHitObjectRecordHitWithIndexMotionNV\n")
22693
0
SLANG_RAW("                    /**/ &__return_val\n")
22694
0
SLANG_RAW("                    /**/ $AccelerationStructure\n")
22695
0
SLANG_RAW("                    /**/ $InstanceIndex\n")
22696
0
SLANG_RAW("                    /**/ $PrimitiveIndex\n")
22697
0
SLANG_RAW("                    /**/ $GeometryIndex\n")
22698
0
SLANG_RAW("                    /**/ $HitKind\n")
22699
0
SLANG_RAW("                    /**/ $HitGroupRecordIndex\n")
22700
0
SLANG_RAW("                    /**/ $origin\n")
22701
0
SLANG_RAW("                    /**/ $tmin\n")
22702
0
SLANG_RAW("                    /**/ $direction\n")
22703
0
SLANG_RAW("                    /**/ $tmax\n")
22704
0
SLANG_RAW("                    /**/ $CurrentTime\n")
22705
0
SLANG_RAW("                    /**/ $attr;\n")
22706
0
SLANG_RAW("            };\n")
22707
0
SLANG_RAW("        }\n")
22708
0
SLANG_RAW("        }\n")
22709
0
SLANG_RAW("    }\n")
22710
0
SLANG_RAW("\n")
22711
0
SLANG_RAW("        /// Creates a HitObject representing a miss based on values explicitly passed as arguments, without\n")
22712
0
SLANG_RAW("        /// tracing a ray. The provided shader table index must reference a valid miss record in the shader\n")
22713
0
SLANG_RAW("        /// table.\n")
22714
0
SLANG_RAW("    [__requiresNVAPI]\n")
22715
0
SLANG_RAW("    [ForceInline]\n")
22716
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22717
0
SLANG_RAW("    static HitObject MakeMiss(\n")
22718
0
SLANG_RAW("        uint MissShaderIndex,\n")
22719
0
SLANG_RAW("        RayDesc Ray)\n")
22720
0
SLANG_RAW("    {\n")
22721
0
SLANG_RAW("        __target_switch\n")
22722
0
SLANG_RAW("        {\n")
22723
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($2=NvMakeMiss($0,$1))\";\n")
22724
0
SLANG_RAW("        case glsl:\n")
22725
0
SLANG_RAW("            __glslMakeMiss(__return_val, MissShaderIndex, Ray.Origin, Ray.TMin, Ray.Direction, Ray.TMax);\n")
22726
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeMissHitObject\";\n")
22727
0
SLANG_RAW("        case spirv:\n")
22728
0
SLANG_RAW("            {\n")
22729
0
SLANG_RAW("                let origin = Ray.Origin;\n")
22730
0
SLANG_RAW("                let direction = Ray.Direction;\n")
22731
0
SLANG_RAW("                let tmin = Ray.TMin;\n")
22732
0
SLANG_RAW("                let tmax = Ray.TMax;\n")
22733
0
SLANG_RAW("                spirv_asm\n")
22734
0
SLANG_RAW("                {\n")
22735
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22736
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
22737
0
SLANG_RAW("                    OpHitObjectRecordMissNV\n")
22738
0
SLANG_RAW("                        /**/ &__return_val\n")
22739
0
SLANG_RAW("                        /**/ $MissShaderIndex\n")
22740
0
SLANG_RAW("                        /**/ $origin\n")
22741
0
SLANG_RAW("                        /**/ $tmin\n")
22742
0
SLANG_RAW("                        /**/ $direction\n")
22743
0
SLANG_RAW("                        /**/ $tmax;\n")
22744
0
SLANG_RAW("                };\n")
22745
0
SLANG_RAW("            }\n")
22746
0
SLANG_RAW("        }\n")
22747
0
SLANG_RAW("    }\n")
22748
0
SLANG_RAW("\n")
22749
0
SLANG_RAW("        /// See MakeMiss but handles Motion\n")
22750
0
SLANG_RAW("        /// Currently only supported on VK\n")
22751
0
SLANG_RAW("    [ForceInline]\n")
22752
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_motion_raygen_closesthit_miss)]\n")
22753
0
SLANG_RAW("    static HitObject MakeMotionMiss(\n")
22754
0
SLANG_RAW("        uint MissShaderIndex,\n")
22755
0
SLANG_RAW("        RayDesc Ray,\n")
22756
0
SLANG_RAW("        float CurrentTime)\n")
22757
0
SLANG_RAW("    {\n")
22758
0
SLANG_RAW("        __target_switch\n")
22759
0
SLANG_RAW("        {\n")
22760
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"($3=NvMakeMotionMiss($0,$1,$2))\";\n")
22761
0
SLANG_RAW("        case glsl:\n")
22762
0
SLANG_RAW("            __glslMakeMotionMiss(__return_val, MissShaderIndex, Ray.Origin, Ray.TMin, Ray.Direction, Ray.TMax, CurrentTime);\n")
22763
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixMakeMissHitObject\";\n")
22764
0
SLANG_RAW("        case spirv:\n")
22765
0
SLANG_RAW("            {\n")
22766
0
SLANG_RAW("                let origin = Ray.Origin;\n")
22767
0
SLANG_RAW("                let direction = Ray.Direction;\n")
22768
0
SLANG_RAW("                let tmin = Ray.TMin;\n")
22769
0
SLANG_RAW("                let tmax = Ray.TMax;\n")
22770
0
SLANG_RAW("                spirv_asm\n")
22771
0
SLANG_RAW("                {\n")
22772
0
SLANG_RAW("                    OpExtension \"SPV_NV_ray_tracing_motion_blur\";\n")
22773
0
SLANG_RAW("                    OpCapability RayTracingMotionBlurNV;\n")
22774
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22775
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
22776
0
SLANG_RAW("                    OpHitObjectRecordMissMotionNV\n")
22777
0
SLANG_RAW("                        /**/ &__return_val\n")
22778
0
SLANG_RAW("                        /**/ $MissShaderIndex\n")
22779
0
SLANG_RAW("                        /**/ $origin\n")
22780
0
SLANG_RAW("                        /**/ $tmin\n")
22781
0
SLANG_RAW("                        /**/ $direction\n")
22782
0
SLANG_RAW("                        /**/ $tmax\n")
22783
0
SLANG_RAW("                        /**/ $CurrentTime;\n")
22784
0
SLANG_RAW("                };\n")
22785
0
SLANG_RAW("            }\n")
22786
0
SLANG_RAW("        }\n")
22787
0
SLANG_RAW("    }\n")
22788
0
SLANG_RAW("\n")
22789
0
SLANG_RAW("        /// Creates a HitObject representing 429496726642949671684294967196NOP429496726642949671684294967197 (no operation) which is neither a hit nor a miss. Invoking a\n")
22790
0
SLANG_RAW("        /// NOP hit object using HitObject::Invoke has no effect. Reordering by hit objects using\n")
22791
0
SLANG_RAW("        /// ReorderThread will group NOP hit objects together. This can be useful in some reordering\n")
22792
0
SLANG_RAW("        /// scenarios where future control flow for some threads is known to process neither a hit nor a\n")
22793
0
SLANG_RAW("        /// miss.\n")
22794
0
SLANG_RAW("    [__requiresNVAPI]\n")
22795
0
SLANG_RAW("    [ForceInline]\n")
22796
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22797
0
SLANG_RAW("    static HitObject MakeNop()\n")
22798
0
SLANG_RAW("    {\n")
22799
0
SLANG_RAW("        __target_switch\n")
22800
0
SLANG_RAW("        {\n")
22801
0
SLANG_RAW("        case hlsl:\n")
22802
0
SLANG_RAW("            __intrinsic_asm \"($0 = NvMakeNop())\";\n")
22803
0
SLANG_RAW("        case glsl:\n")
22804
0
SLANG_RAW("            __glslMakeNop(__return_val);\n")
22805
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixMakeNopHitObject\";\n")
22806
0
SLANG_RAW("        case spirv:\n")
22807
0
SLANG_RAW("            spirv_asm\n")
22808
0
SLANG_RAW("            {\n")
22809
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22810
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22811
0
SLANG_RAW("                OpHitObjectRecordEmptyNV\n")
22812
0
SLANG_RAW("                    /**/ &__return_val;\n")
22813
0
SLANG_RAW("            };\n")
22814
0
SLANG_RAW("        }\n")
22815
0
SLANG_RAW("    }\n")
22816
0
SLANG_RAW("\n")
22817
0
SLANG_RAW("    [require(hlsl, ser)]\n")
22818
0
SLANG_RAW("    __generic<payload_t>\n")
22819
0
SLANG_RAW("    static void __InvokeHLSL(\n")
22820
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22821
0
SLANG_RAW("        HitObject HitOrMiss,\n")
22822
0
SLANG_RAW("        inout payload_t Payload)\n")
22823
0
SLANG_RAW("    {\n")
22824
0
SLANG_RAW("        __target_switch\n")
22825
0
SLANG_RAW("        {\n")
22826
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvInvokeHitObject\";\n")
22827
0
SLANG_RAW("        }\n")
22828
0
SLANG_RAW("    }\n")
22829
0
SLANG_RAW("\n")
22830
0
SLANG_RAW("        /// Invokes closesthit or miss shading for the specified hit object. In case of a NOP HitObject, no\n")
22831
0
SLANG_RAW("        /// shader is invoked.\n")
22832
0
SLANG_RAW("    [__requiresNVAPI]\n")
22833
0
SLANG_RAW("    [ForceInline]\n")
22834
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22835
0
SLANG_RAW("    static void Invoke<payload_t>(\n")
22836
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
22837
0
SLANG_RAW("        HitObject HitOrMiss,\n")
22838
0
SLANG_RAW("        inout payload_t Payload)\n")
22839
0
SLANG_RAW("    {\n")
22840
0
SLANG_RAW("        __target_switch\n")
22841
0
SLANG_RAW("        {\n")
22842
0
SLANG_RAW("        case hlsl:\n")
22843
0
SLANG_RAW("            __InvokeHLSL(\n")
22844
0
SLANG_RAW("                AccelerationStructure,\n")
22845
0
SLANG_RAW("                HitOrMiss,\n")
22846
0
SLANG_RAW("                __forceVarIntoRayPayloadStructTemporarily(Payload));\n")
22847
0
SLANG_RAW("        case glsl:\n")
22848
0
SLANG_RAW("            {\n")
22849
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22850
0
SLANG_RAW("                static payload_t p;\n")
22851
0
SLANG_RAW("\n")
22852
0
SLANG_RAW("                // Save the payload\n")
22853
0
SLANG_RAW("                p = Payload;\n")
22854
0
SLANG_RAW("\n")
22855
0
SLANG_RAW("                __glslInvoke(HitOrMiss, __rayPayloadLocation(p));\n")
22856
0
SLANG_RAW("\n")
22857
0
SLANG_RAW("                // Write payload result\n")
22858
0
SLANG_RAW("                Payload = p;\n")
22859
0
SLANG_RAW("            }\n")
22860
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixInvoke\";\n")
22861
0
SLANG_RAW("        case spirv:\n")
22862
0
SLANG_RAW("            {\n")
22863
0
SLANG_RAW("                [__vulkanRayPayload]\n")
22864
0
SLANG_RAW("                static payload_t p;\n")
22865
0
SLANG_RAW("\n")
22866
0
SLANG_RAW("                // Save the payload\n")
22867
0
SLANG_RAW("                p = Payload;\n")
22868
0
SLANG_RAW("\n")
22869
0
SLANG_RAW("                spirv_asm\n")
22870
0
SLANG_RAW("                {\n")
22871
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22872
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22873
0
SLANG_RAW("                    OpHitObjectExecuteShaderNV\n")
22874
0
SLANG_RAW("                        /**/ &HitOrMiss\n")
22875
0
SLANG_RAW("                        /**/ &p;\n")
22876
0
SLANG_RAW("                };\n")
22877
0
SLANG_RAW("\n")
22878
0
SLANG_RAW("                // Write payload result\n")
22879
0
SLANG_RAW("                Payload = p;\n")
22880
0
SLANG_RAW("            }\n")
22881
0
SLANG_RAW("        }\n")
22882
0
SLANG_RAW("    }\n")
22883
0
SLANG_RAW("\n")
22884
0
SLANG_RAW("        /// Returns true if the HitObject encodes a miss, otherwise returns false.\n")
22885
0
SLANG_RAW("    [__requiresNVAPI]\n")
22886
0
SLANG_RAW("    [ForceInline]\n")
22887
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22888
0
SLANG_RAW("    bool IsMiss()\n")
22889
0
SLANG_RAW("    {\n")
22890
0
SLANG_RAW("        __target_switch\n")
22891
0
SLANG_RAW("        {\n")
22892
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".IsMiss\";\n")
22893
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectIsMissNV($0)\";\n")
22894
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectIsMiss\";\n")
22895
0
SLANG_RAW("        case spirv:\n")
22896
0
SLANG_RAW("            return spirv_asm\n")
22897
0
SLANG_RAW("            {\n")
22898
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22899
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22900
0
SLANG_RAW("                result:$$bool = OpHitObjectIsMissNV &this;\n")
22901
0
SLANG_RAW("            };\n")
22902
0
SLANG_RAW("        }\n")
22903
0
SLANG_RAW("    }\n")
22904
0
SLANG_RAW("\n")
22905
0
SLANG_RAW("        /// Returns true if the HitObject encodes a hit, otherwise returns false.\n")
22906
0
SLANG_RAW("    [__requiresNVAPI]\n")
22907
0
SLANG_RAW("    [ForceInline]\n")
22908
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22909
0
SLANG_RAW("    bool IsHit()\n")
22910
0
SLANG_RAW("    {\n")
22911
0
SLANG_RAW("        __target_switch\n")
22912
0
SLANG_RAW("        {\n")
22913
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".IsHit\";\n")
22914
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectIsHitNV($0)\";\n")
22915
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectIsHit\";\n")
22916
0
SLANG_RAW("        case spirv:\n")
22917
0
SLANG_RAW("            return spirv_asm\n")
22918
0
SLANG_RAW("            {\n")
22919
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22920
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22921
0
SLANG_RAW("                result:$$bool = OpHitObjectIsHitNV &this;\n")
22922
0
SLANG_RAW("            };\n")
22923
0
SLANG_RAW("        }\n")
22924
0
SLANG_RAW("    }\n")
22925
0
SLANG_RAW("\n")
22926
0
SLANG_RAW("        /// Returns true if the HitObject encodes a nop, otherwise returns false.\n")
22927
0
SLANG_RAW("    [__requiresNVAPI]\n")
22928
0
SLANG_RAW("    [ForceInline]\n")
22929
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22930
0
SLANG_RAW("    bool IsNop()\n")
22931
0
SLANG_RAW("    {\n")
22932
0
SLANG_RAW("        __target_switch\n")
22933
0
SLANG_RAW("        {\n")
22934
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".IsNop\";\n")
22935
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectIsEmptyNV($0)\";\n")
22936
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectIsNop\";\n")
22937
0
SLANG_RAW("        case spirv:\n")
22938
0
SLANG_RAW("            return spirv_asm\n")
22939
0
SLANG_RAW("            {\n")
22940
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22941
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22942
0
SLANG_RAW("                result:$$bool = OpHitObjectIsEmptyNV &this;\n")
22943
0
SLANG_RAW("            };\n")
22944
0
SLANG_RAW("        }\n")
22945
0
SLANG_RAW("    }\n")
22946
0
SLANG_RAW("\n")
22947
0
SLANG_RAW("        /// Queries ray properties from HitObject. Valid if the hit object represents a hit or a miss.\n")
22948
0
SLANG_RAW("    [__requiresNVAPI]\n")
22949
0
SLANG_RAW("    [ForceInline]\n")
22950
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22951
0
SLANG_RAW("    RayDesc GetRayDesc()\n")
22952
0
SLANG_RAW("    {\n")
22953
0
SLANG_RAW("        __target_switch\n")
22954
0
SLANG_RAW("        {\n")
22955
0
SLANG_RAW("        case hlsl:\n")
22956
0
SLANG_RAW("            __intrinsic_asm \".GetRayDesc\";\n")
22957
0
SLANG_RAW("        case glsl:\n")
22958
0
SLANG_RAW("            {\n")
22959
0
SLANG_RAW("                RayDesc ray = { __glslGetRayWorldOrigin(), __glslGetTMin(), __glslGetRayWorldDirection(), __glslGetTMax() };\n")
22960
0
SLANG_RAW("                return ray;\n")
22961
0
SLANG_RAW("            }\n")
22962
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixHitObjectGetRayDesc\";\n")
22963
0
SLANG_RAW("        case spirv:\n")
22964
0
SLANG_RAW("            return spirv_asm\n")
22965
0
SLANG_RAW("            {\n")
22966
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22967
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22968
0
SLANG_RAW("                %origin:$$float3 = OpHitObjectGetWorldRayOriginNV &this;\n")
22969
0
SLANG_RAW("                %tmin:$$float = OpHitObjectGetRayTMinNV &this;\n")
22970
0
SLANG_RAW("                %direction:$$float3 = OpHitObjectGetWorldRayDirectionNV &this;\n")
22971
0
SLANG_RAW("                %tmax:$$float = OpHitObjectGetRayTMaxNV &this;\n")
22972
0
SLANG_RAW("                result:$$RayDesc = OpCompositeConstruct %origin %tmin %direction %tmax;\n")
22973
0
SLANG_RAW("            };\n")
22974
0
SLANG_RAW("        }\n")
22975
0
SLANG_RAW("    }\n")
22976
0
SLANG_RAW("\n")
22977
0
SLANG_RAW("        /// Queries shader table index from HitObject. Valid if the hit object represents a hit or a miss.\n")
22978
0
SLANG_RAW("    [__requiresNVAPI]\n")
22979
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
22980
0
SLANG_RAW("    [ForceInline]\n")
22981
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
22982
0
SLANG_RAW("    uint GetShaderTableIndex()\n")
22983
0
SLANG_RAW("    {\n")
22984
0
SLANG_RAW("        __target_switch\n")
22985
0
SLANG_RAW("        {\n")
22986
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetShaderTableIndex\";\n")
22987
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetShaderBindingTableRecordIndexNV($0)\";\n")
22988
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetSbtRecordIndex\";\n")
22989
0
SLANG_RAW("        case spirv:\n")
22990
0
SLANG_RAW("            return spirv_asm\n")
22991
0
SLANG_RAW("            {\n")
22992
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
22993
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
22994
0
SLANG_RAW("                result:$$uint = OpHitObjectGetShaderBindingTableRecordIndexNV &this;\n")
22995
0
SLANG_RAW("            };\n")
22996
0
SLANG_RAW("        }\n")
22997
0
SLANG_RAW("    }\n")
22998
0
SLANG_RAW("\n")
22999
0
SLANG_RAW("    [__requiresNVAPI]\n")
23000
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23001
0
SLANG_RAW("    [ForceInline]\n")
23002
0
SLANG_RAW("    [require(cuda_hlsl, ser_raygen_closesthit_miss)]\n")
23003
0
SLANG_RAW("    uint SetShaderTableIndex(uint RecordIndex)\n")
23004
0
SLANG_RAW("    {\n")
23005
0
SLANG_RAW("        __target_switch\n")
23006
0
SLANG_RAW("        {\n")
23007
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".SetShaderTableIndex\";\n")
23008
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectSetSbtRecordIndex\";\n")
23009
0
SLANG_RAW("        }\n")
23010
0
SLANG_RAW("    }\n")
23011
0
SLANG_RAW("        /// Returns the instance index of a hit. Valid if the hit object represents a hit.\n")
23012
0
SLANG_RAW("    [__requiresNVAPI]\n")
23013
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23014
0
SLANG_RAW("    [ForceInline]\n")
23015
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23016
0
SLANG_RAW("    uint GetInstanceIndex()\n")
23017
0
SLANG_RAW("    {\n")
23018
0
SLANG_RAW("        __target_switch\n")
23019
0
SLANG_RAW("        {\n")
23020
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetInstanceIndex\";\n")
23021
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetInstanceIdNV($0)\";\n")
23022
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetInstanceIndex\";\n")
23023
0
SLANG_RAW("        case spirv:\n")
23024
0
SLANG_RAW("            return spirv_asm\n")
23025
0
SLANG_RAW("            {\n")
23026
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23027
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23028
0
SLANG_RAW("                result:$$uint = OpHitObjectGetInstanceIdNV &this;\n")
23029
0
SLANG_RAW("            };\n")
23030
0
SLANG_RAW("        }\n")
23031
0
SLANG_RAW("    }\n")
23032
0
SLANG_RAW("\n")
23033
0
SLANG_RAW("        /// Returns the instance ID of a hit. Valid if the hit object represents a hit.\n")
23034
0
SLANG_RAW("    [__requiresNVAPI]\n")
23035
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23036
0
SLANG_RAW("    [ForceInline]\n")
23037
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23038
0
SLANG_RAW("    uint GetInstanceID()\n")
23039
0
SLANG_RAW("    {\n")
23040
0
SLANG_RAW("        __target_switch\n")
23041
0
SLANG_RAW("        {\n")
23042
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetInstanceID\";\n")
23043
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetInstanceCustomIndexNV($0)\";\n")
23044
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetInstanceId\";\n")
23045
0
SLANG_RAW("        case spirv:\n")
23046
0
SLANG_RAW("            return spirv_asm\n")
23047
0
SLANG_RAW("            {\n")
23048
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23049
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23050
0
SLANG_RAW("                result:$$uint = OpHitObjectGetInstanceCustomIndexNV &this;\n")
23051
0
SLANG_RAW("            };\n")
23052
0
SLANG_RAW("        }\n")
23053
0
SLANG_RAW("    }\n")
23054
0
SLANG_RAW("\n")
23055
0
SLANG_RAW("        /// Returns the geometry index of a hit. Valid if the hit object represents a hit.\n")
23056
0
SLANG_RAW("    [__requiresNVAPI]\n")
23057
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23058
0
SLANG_RAW("    [ForceInline]\n")
23059
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23060
0
SLANG_RAW("    uint GetGeometryIndex()\n")
23061
0
SLANG_RAW("    {\n")
23062
0
SLANG_RAW("        __target_switch\n")
23063
0
SLANG_RAW("        {\n")
23064
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetGeometryIndex\";\n")
23065
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetGeometryIndexNV($0)\";\n")
23066
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetSbtGASIndex\";\n")
23067
0
SLANG_RAW("        case spirv:\n")
23068
0
SLANG_RAW("            return spirv_asm\n")
23069
0
SLANG_RAW("            {\n")
23070
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23071
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23072
0
SLANG_RAW("                result:$$uint = OpHitObjectGetGeometryIndexNV &this;\n")
23073
0
SLANG_RAW("            };\n")
23074
0
SLANG_RAW("        }\n")
23075
0
SLANG_RAW("    }\n")
23076
0
SLANG_RAW("\n")
23077
0
SLANG_RAW("        /// Returns the primitive index of a hit. Valid if the hit object represents a hit.\n")
23078
0
SLANG_RAW("    [__requiresNVAPI]\n")
23079
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23080
0
SLANG_RAW("    [ForceInline]\n")
23081
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23082
0
SLANG_RAW("    uint GetPrimitiveIndex()\n")
23083
0
SLANG_RAW("    {\n")
23084
0
SLANG_RAW("        __target_switch\n")
23085
0
SLANG_RAW("        {\n")
23086
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetPrimitiveIndex\";\n")
23087
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetPrimitiveIndexNV($0)\";\n")
23088
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetPrimitiveIndex\";\n")
23089
0
SLANG_RAW("        case spirv:\n")
23090
0
SLANG_RAW("            return spirv_asm\n")
23091
0
SLANG_RAW("            {\n")
23092
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23093
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23094
0
SLANG_RAW("                result:$$uint = OpHitObjectGetPrimitiveIndexNV &this;\n")
23095
0
SLANG_RAW("            };\n")
23096
0
SLANG_RAW("        }\n")
23097
0
SLANG_RAW("    }\n")
23098
0
SLANG_RAW("\n")
23099
0
SLANG_RAW("        /// Returns the hit kind. Valid if the hit object represents a hit.\n")
23100
0
SLANG_RAW("    [__requiresNVAPI]\n")
23101
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23102
0
SLANG_RAW("    [ForceInline]\n")
23103
0
SLANG_RAW("    [require(glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23104
0
SLANG_RAW("    uint GetHitKind()\n")
23105
0
SLANG_RAW("    {\n")
23106
0
SLANG_RAW("        __target_switch\n")
23107
0
SLANG_RAW("        {\n")
23108
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetHitKind\";\n")
23109
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetHitKindNV($0)\";\n")
23110
0
SLANG_RAW("        case spirv:\n")
23111
0
SLANG_RAW("            return spirv_asm\n")
23112
0
SLANG_RAW("            {\n")
23113
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23114
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23115
0
SLANG_RAW("                result:$$uint = OpHitObjectGetHitKindNV &this;\n")
23116
0
SLANG_RAW("            };\n")
23117
0
SLANG_RAW("        }\n")
23118
0
SLANG_RAW("    }\n")
23119
0
SLANG_RAW("\n")
23120
0
SLANG_RAW("    /// Returns the cluster ID of the current hit. Valid if the hit object represents a hit.\n")
23121
0
SLANG_RAW("    [__requiresNVAPI]\n")
23122
0
SLANG_RAW("    __glsl_extension(GL_NV_cluster_acceleration_structure)\n")
23123
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23124
0
SLANG_RAW("    [ForceInline]\n")
23125
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23126
0
SLANG_RAW("    int GetClusterID()\n")
23127
0
SLANG_RAW("    {\n")
23128
0
SLANG_RAW("        __target_switch\n")
23129
0
SLANG_RAW("        {\n")
23130
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetClusterID\";\n")
23131
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetClusterIdNV($0)\";\n")
23132
0
SLANG_RAW("        case cuda: __intrinsic_asm \"slangOptixHitObjectGetClusterId\";\n")
23133
0
SLANG_RAW("        case spirv:\n")
23134
0
SLANG_RAW("            return spirv_asm\n")
23135
0
SLANG_RAW("            {\n")
23136
0
SLANG_RAW("                OpExtension \"SPV_NV_cluster_acceleration_structure\";\n")
23137
0
SLANG_RAW("                OpCapability RayTracingClusterAccelerationStructureNV;\n")
23138
0
SLANG_RAW("                result:$$int = OpHitObjectGetClusterIdNV &this;\n")
23139
0
SLANG_RAW("            };\n")
23140
0
SLANG_RAW("        }\n")
23141
0
SLANG_RAW("    }\n")
23142
0
SLANG_RAW("\n")
23143
0
SLANG_RAW("    [__requiresNVAPI]\n")
23144
0
SLANG_RAW("    [NonUniformReturn]\n")
23145
0
SLANG_RAW("    [require(cuda_hlsl_spirv, raytracing_lss_ho)]\n")
23146
0
SLANG_RAW("    float4 GetSpherePositionAndRadius()\n")
23147
0
SLANG_RAW("    {\n")
23148
0
SLANG_RAW("        __target_switch\n")
23149
0
SLANG_RAW("        {\n")
23150
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetSphereObjectPositionAndRadius\";\n")
23151
0
SLANG_RAW("        case cuda:\n")
23152
0
SLANG_RAW("            {\n")
23153
0
SLANG_RAW("                __intrinsic_asm \"optixHitObjectGetSpherePositionAndRadius\";\n")
23154
0
SLANG_RAW("            }\n")
23155
0
SLANG_RAW("        case spirv:\n")
23156
0
SLANG_RAW("            return spirv_asm\n")
23157
0
SLANG_RAW("            {\n")
23158
0
SLANG_RAW("                OpExtension \"SPV_NV_linear_swept_spheres\";\n")
23159
0
SLANG_RAW("                OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
23160
0
SLANG_RAW("                OpCapability RayTracingSpheresGeometryNV;\n")
23161
0
SLANG_RAW("                %position:$$float3 = OpHitObjectGetSpherePositionNV &this;\n")
23162
0
SLANG_RAW("                %radius:$$float = OpHitObjectGetSphereRadiusNV &this;\n")
23163
0
SLANG_RAW("                result:$$float4 = OpCompositeConstruct %position %radius;\n")
23164
0
SLANG_RAW("            };\n")
23165
0
SLANG_RAW("        }\n")
23166
0
SLANG_RAW("    }\n")
23167
0
SLANG_RAW("\n")
23168
0
SLANG_RAW("    [__requiresNVAPI]\n")
23169
0
SLANG_RAW("    [NonUniformReturn]\n")
23170
0
SLANG_RAW("    [require(cuda_hlsl_spirv, raytracing_lss_ho)]\n")
23171
0
SLANG_RAW("    float2x4 GetLssPositionsAndRadii()\n")
23172
0
SLANG_RAW("    {\n")
23173
0
SLANG_RAW("        __target_switch\n")
23174
0
SLANG_RAW("        {\n")
23175
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetLssObjectPositionsAndRadii\";\n")
23176
0
SLANG_RAW("        case cuda:\n")
23177
0
SLANG_RAW("            {\n")
23178
0
SLANG_RAW("                __intrinsic_asm \"optixHitObjectGetLssPositionsAndRadii\";\n")
23179
0
SLANG_RAW("            }\n")
23180
0
SLANG_RAW("        case spirv:\n")
23181
0
SLANG_RAW("            return spirv_asm\n")
23182
0
SLANG_RAW("            {\n")
23183
0
SLANG_RAW("                OpExtension \"SPV_NV_linear_swept_spheres\";\n")
23184
0
SLANG_RAW("                OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
23185
0
SLANG_RAW("                OpCapability RayTracingSpheresGeometryNV;\n")
23186
0
SLANG_RAW("                %positions:$$float3[2] = OpHitObjectGetLSSPositionsNV &this;\n")
23187
0
SLANG_RAW("                %radii:$$float[2] = OpHitObjectGetLSSRadiiNV &this;\n")
23188
0
SLANG_RAW("                %r0:$$float = OpCompositeExtract %radii 0;\n")
23189
0
SLANG_RAW("                %r1:$$float = OpCompositeExtract %radii 1;\n")
23190
0
SLANG_RAW("                %p0:$$float3 = OpCompositeExtract %positions 0;\n")
23191
0
SLANG_RAW("                %p1:$$float3 = OpCompositeExtract %positions 1;\n")
23192
0
SLANG_RAW("                %a:$$float4 = OpCompositeConstruct %p0 %r0;\n")
23193
0
SLANG_RAW("                %b:$$float4 = OpCompositeConstruct %p1 %r1;\n")
23194
0
SLANG_RAW("                result:$$float2x4 = OpCompositeConstruct %a %b;\n")
23195
0
SLANG_RAW("            };\n")
23196
0
SLANG_RAW("        }\n")
23197
0
SLANG_RAW("    }\n")
23198
0
SLANG_RAW("\n")
23199
0
SLANG_RAW("    [__requiresNVAPI]\n")
23200
0
SLANG_RAW("    [NonUniformReturn]\n")
23201
0
SLANG_RAW("    [require(cuda_hlsl_spirv, raytracing_lss_ho)]\n")
23202
0
SLANG_RAW("    bool IsSphereHit()\n")
23203
0
SLANG_RAW("    {\n")
23204
0
SLANG_RAW("        __target_switch\n")
23205
0
SLANG_RAW("        {\n")
23206
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".IsSphereHit\";\n")
23207
0
SLANG_RAW("        case cuda:\n")
23208
0
SLANG_RAW("            {\n")
23209
0
SLANG_RAW("                __intrinsic_asm \"optixHitObjectIsSphereHit\";\n")
23210
0
SLANG_RAW("            }\n")
23211
0
SLANG_RAW("        case spirv:\n")
23212
0
SLANG_RAW("            return spirv_asm\n")
23213
0
SLANG_RAW("            {\n")
23214
0
SLANG_RAW("                OpExtension \"SPV_NV_linear_swept_spheres\";\n")
23215
0
SLANG_RAW("                OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
23216
0
SLANG_RAW("                result:$$bool = OpHitObjectIsSphereHitNV &this;\n")
23217
0
SLANG_RAW("            };\n")
23218
0
SLANG_RAW("        }\n")
23219
0
SLANG_RAW("    }\n")
23220
0
SLANG_RAW("\n")
23221
0
SLANG_RAW("    [__requiresNVAPI]\n")
23222
0
SLANG_RAW("    [NonUniformReturn]\n")
23223
0
SLANG_RAW("    [require(cuda_hlsl_spirv, raytracing_lss_ho)]\n")
23224
0
SLANG_RAW("    bool IsLssHit()\n")
23225
0
SLANG_RAW("    {\n")
23226
0
SLANG_RAW("        __target_switch\n")
23227
0
SLANG_RAW("        {\n")
23228
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".IsLssHit\";\n")
23229
0
SLANG_RAW("        case cuda:\n")
23230
0
SLANG_RAW("            {\n")
23231
0
SLANG_RAW("                __intrinsic_asm \"optixHitObjectIsLSSHit\";\n")
23232
0
SLANG_RAW("            }\n")
23233
0
SLANG_RAW("        case spirv:\n")
23234
0
SLANG_RAW("            return spirv_asm\n")
23235
0
SLANG_RAW("            {\n")
23236
0
SLANG_RAW("                OpExtension \"SPV_NV_linear_swept_spheres\";\n")
23237
0
SLANG_RAW("                OpCapability RayTracingLinearSweptSpheresGeometryNV;\n")
23238
0
SLANG_RAW("                result:$$bool = OpHitObjectIsLSSHitNV &this;\n")
23239
0
SLANG_RAW("            };\n")
23240
0
SLANG_RAW("        }\n")
23241
0
SLANG_RAW("    }\n")
23242
0
SLANG_RAW("\n")
23243
0
SLANG_RAW("    [__requiresNVAPI]\n")
23244
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23245
0
SLANG_RAW("    [ForceInline]\n")
23246
0
SLANG_RAW("    [require(glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23247
0
SLANG_RAW("    float4x3 GetWorldToObject()\n")
23248
0
SLANG_RAW("    {\n")
23249
0
SLANG_RAW("        __target_switch\n")
23250
0
SLANG_RAW("        {\n")
23251
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetWorldToObject\";\n")
23252
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetWorldToObjectNV($0)\";\n")
23253
0
SLANG_RAW("        case spirv:\n")
23254
0
SLANG_RAW("            return spirv_asm\n")
23255
0
SLANG_RAW("            {\n")
23256
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23257
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23258
0
SLANG_RAW("                result:$$float4x3 = OpHitObjectGetWorldToObjectNV &this;\n")
23259
0
SLANG_RAW("            };\n")
23260
0
SLANG_RAW("        }\n")
23261
0
SLANG_RAW("    }\n")
23262
0
SLANG_RAW("\n")
23263
0
SLANG_RAW("    [__requiresNVAPI]\n")
23264
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23265
0
SLANG_RAW("    [ForceInline]\n")
23266
0
SLANG_RAW("    [require(glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23267
0
SLANG_RAW("    float4x3 GetObjectToWorld()\n")
23268
0
SLANG_RAW("    {\n")
23269
0
SLANG_RAW("        __target_switch\n")
23270
0
SLANG_RAW("        {\n")
23271
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".GetObjectToWorld\";\n")
23272
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetObjectToWorldNV($0)\";\n")
23273
0
SLANG_RAW("        case spirv:\n")
23274
0
SLANG_RAW("            return spirv_asm\n")
23275
0
SLANG_RAW("            {\n")
23276
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23277
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23278
0
SLANG_RAW("                result:$$float4x3 = OpHitObjectGetObjectToWorldNV &this;\n")
23279
0
SLANG_RAW("            };\n")
23280
0
SLANG_RAW("        }\n")
23281
0
SLANG_RAW("    }\n")
23282
0
SLANG_RAW("\n")
23283
0
SLANG_RAW("    [ForceInline]\n")
23284
0
SLANG_RAW("    [require(glsl_spirv, ser_raygen_closesthit_miss)]\n")
23285
0
SLANG_RAW("    float GetCurrentTime() {\n")
23286
0
SLANG_RAW("        __target_switch\n")
23287
0
SLANG_RAW("        {\n")
23288
0
SLANG_RAW("        case glsl:\n")
23289
0
SLANG_RAW("            __intrinsic_asm \"hitObjectGetCurrentTimeNV($0)\";\n")
23290
0
SLANG_RAW("        case spirv:\n")
23291
0
SLANG_RAW("            return spirv_asm\n")
23292
0
SLANG_RAW("            {\n")
23293
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23294
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23295
0
SLANG_RAW("                result:$$float = OpHitObjectGetCurrentTimeNV &this\n")
23296
0
SLANG_RAW("            };\n")
23297
0
SLANG_RAW("        }\n")
23298
0
SLANG_RAW("    }\n")
23299
0
SLANG_RAW("\n")
23300
0
SLANG_RAW("    [ForceInline]\n")
23301
0
SLANG_RAW("    [require(glsl_spirv, ser_raygen_closesthit_miss)]\n")
23302
0
SLANG_RAW("    float3 GetObjectRayOrigin() {\n")
23303
0
SLANG_RAW("        __target_switch\n")
23304
0
SLANG_RAW("        {\n")
23305
0
SLANG_RAW("        case glsl:\n")
23306
0
SLANG_RAW("            __intrinsic_asm \"hitObjectGetObjectRayOriginNV($0)\";\n")
23307
0
SLANG_RAW("        case spirv:\n")
23308
0
SLANG_RAW("            return spirv_asm\n")
23309
0
SLANG_RAW("            {\n")
23310
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23311
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23312
0
SLANG_RAW("                result:$$float3 = OpHitObjectGetObjectRayOriginNV &this\n")
23313
0
SLANG_RAW("            };\n")
23314
0
SLANG_RAW("        }\n")
23315
0
SLANG_RAW("    }\n")
23316
0
SLANG_RAW("\n")
23317
0
SLANG_RAW("    [ForceInline]\n")
23318
0
SLANG_RAW("    [require(glsl_spirv, ser_raygen_closesthit_miss)]\n")
23319
0
SLANG_RAW("    float3 GetObjectRayDirection() {\n")
23320
0
SLANG_RAW("        __target_switch\n")
23321
0
SLANG_RAW("        {\n")
23322
0
SLANG_RAW("        case glsl:\n")
23323
0
SLANG_RAW("            __intrinsic_asm \"hitObjectGetObjectRayDirectionNV($0)\";\n")
23324
0
SLANG_RAW("        case spirv:\n")
23325
0
SLANG_RAW("            return spirv_asm\n")
23326
0
SLANG_RAW("            {\n")
23327
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23328
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23329
0
SLANG_RAW("                result:$$float3 = OpHitObjectGetObjectRayDirectionNV &this\n")
23330
0
SLANG_RAW("            };\n")
23331
0
SLANG_RAW("        }\n")
23332
0
SLANG_RAW("    }\n")
23333
0
SLANG_RAW("\n")
23334
0
SLANG_RAW("    [ForceInline]\n")
23335
0
SLANG_RAW("    [require(glsl_spirv, ser_raygen_closesthit_miss)]\n")
23336
0
SLANG_RAW("    uint2 GetShaderRecordBufferHandle() {\n")
23337
0
SLANG_RAW("        __target_switch\n")
23338
0
SLANG_RAW("        {\n")
23339
0
SLANG_RAW("        case glsl:\n")
23340
0
SLANG_RAW("            __intrinsic_asm \"hitObjectGetShaderRecordBufferHandleNV($0)\";\n")
23341
0
SLANG_RAW("        case spirv:\n")
23342
0
SLANG_RAW("            return spirv_asm\n")
23343
0
SLANG_RAW("            {\n")
23344
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23345
0
SLANG_RAW("                OpCapability ShaderInvocationReorderNV;\n")
23346
0
SLANG_RAW("                result:$$uint2 = OpHitObjectGetShaderRecordBufferHandleNV &this\n")
23347
0
SLANG_RAW("            };\n")
23348
0
SLANG_RAW("        }\n")
23349
0
SLANG_RAW("    }\n")
23350
0
SLANG_RAW("\n")
23351
0
SLANG_RAW("    /// Returns the attributes of a hit. Valid if the hit object represents a hit or a miss.\n")
23352
0
SLANG_RAW("    [ForceInline]\n")
23353
0
SLANG_RAW("    [require(cuda_glsl_hlsl_spirv, ser_raygen_closesthit_miss)]\n")
23354
0
SLANG_RAW("    attr_t GetAttributes<attr_t>()\n")
23355
0
SLANG_RAW("    {\n")
23356
0
SLANG_RAW("        __target_switch\n")
23357
0
SLANG_RAW("        {\n")
23358
0
SLANG_RAW("        case hlsl:\n")
23359
0
SLANG_RAW("            {\n")
23360
0
SLANG_RAW("                attr_t v;\n")
23361
0
SLANG_RAW("                __hlslGetAttributesFromHitObject(v);\n")
23362
0
SLANG_RAW("                return v;\n")
23363
0
SLANG_RAW("            }\n")
23364
0
SLANG_RAW("        case glsl:\n")
23365
0
SLANG_RAW("            {\n")
23366
0
SLANG_RAW("                // Work out the location\n")
23367
0
SLANG_RAW("                int attributeLocation = __hitObjectAttributesLocation(__hitObjectAttributes<attr_t>());\n")
23368
0
SLANG_RAW("\n")
23369
0
SLANG_RAW("                // Load the attributes from the location\n")
23370
0
SLANG_RAW("                __glslGetAttributes(attributeLocation);\n")
23371
0
SLANG_RAW("\n")
23372
0
SLANG_RAW("                // Return the attributes\n")
23373
0
SLANG_RAW("                return __hitObjectAttributes<attr_t>();\n")
23374
0
SLANG_RAW("            }\n")
23375
0
SLANG_RAW("        case cuda: __intrinsic_asm \"optixHitObjectGetAttribute<$TR>($0)\";\n")
23376
0
SLANG_RAW("        case spirv:\n")
23377
0
SLANG_RAW("            {\n")
23378
0
SLANG_RAW("                __Addr<attr_t> attr = __allocHitObjectAttributes<attr_t>();\n")
23379
0
SLANG_RAW("                spirv_asm\n")
23380
0
SLANG_RAW("                {\n")
23381
0
SLANG_RAW("                    OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23382
0
SLANG_RAW("                    OpCapability ShaderInvocationReorderNV;\n")
23383
0
SLANG_RAW("                    OpHitObjectGetAttributesNV &this $attr;\n")
23384
0
SLANG_RAW("                };\n")
23385
0
SLANG_RAW("                return *attr;\n")
23386
0
SLANG_RAW("            }\n")
23387
0
SLANG_RAW("        }\n")
23388
0
SLANG_RAW("    }\n")
23389
0
SLANG_RAW("        /// Loads a root constant from the local root table referenced by the hit object. Valid if the hit object\n")
23390
0
SLANG_RAW("        /// represents a hit or a miss. RootConstantOffsetInBytes must be a multiple of 4.\n")
23391
0
SLANG_RAW("    [__requiresNVAPI]\n")
23392
0
SLANG_RAW("    [require(cuda_hlsl, ser_raygen_closesthit_miss)]\n")
23393
0
SLANG_RAW("    uint LoadLocalRootTableConstant(uint RootConstantOffsetInBytes)\n")
23394
0
SLANG_RAW("    {\n")
23395
0
SLANG_RAW("        __target_switch\n")
23396
0
SLANG_RAW("        {\n")
23397
0
SLANG_RAW("        case hlsl: __intrinsic_asm \".LoadLocalRootTableConstant\";\n")
23398
0
SLANG_RAW("        case cuda: __intrinsic_asm \"(*(uint32_t*)((char*)optixHitObjectGetSbtDataPointer()+$1))\";\n")
23399
0
SLANG_RAW("        }\n")
23400
0
SLANG_RAW("    }\n")
23401
0
SLANG_RAW("\n")
23402
0
SLANG_RAW("    ///\n")
23403
0
SLANG_RAW("    /// !!!! Internal NVAPI HLSL impl. Not part of interface! !!!!!!!!!!!!\n")
23404
0
SLANG_RAW("    ///\n")
23405
0
SLANG_RAW("\n")
23406
0
SLANG_RAW("    [__requiresNVAPI]\n")
23407
0
SLANG_RAW("    [require(hlsl, ser_raygen_closesthit_miss)]\n")
23408
0
SLANG_RAW("    void __hlslGetAttributesFromHitObject<T>(out T t)\n")
23409
0
SLANG_RAW("    {\n")
23410
0
SLANG_RAW("        __target_switch\n")
23411
0
SLANG_RAW("        {\n")
23412
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvGetAttributesFromHitObject($0, $1)\";\n")
23413
0
SLANG_RAW("        }\n")
23414
0
SLANG_RAW("    }\n")
23415
0
SLANG_RAW("\n")
23416
0
SLANG_RAW("    [__requiresNVAPI]\n")
23417
0
SLANG_RAW("    [require(hlsl, ser_raygen_closesthit_miss)]\n")
23418
0
SLANG_RAW("    static void __hlslMakeHitWithRecordIndex<attr_t>(\n")
23419
0
SLANG_RAW("        uint HitGroupRecordIndex,\n")
23420
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
23421
0
SLANG_RAW("        uint InstanceIndex,\n")
23422
0
SLANG_RAW("        uint GeometryIndex,\n")
23423
0
SLANG_RAW("        uint PrimitiveIndex,\n")
23424
0
SLANG_RAW("        uint HitKind,\n")
23425
0
SLANG_RAW("        RayDesc Ray,\n")
23426
0
SLANG_RAW("        attr_t attributes,\n")
23427
0
SLANG_RAW("        out HitObject hitObj)\n")
23428
0
SLANG_RAW("    {\n")
23429
0
SLANG_RAW("        __target_switch\n")
23430
0
SLANG_RAW("        {\n")
23431
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvMakeHitWithRecordIndex\";\n")
23432
0
SLANG_RAW("        }\n")
23433
0
SLANG_RAW("    }\n")
23434
0
SLANG_RAW("\n")
23435
0
SLANG_RAW("    [__requiresNVAPI]\n")
23436
0
SLANG_RAW("    [require(hlsl, ser_raygen_closesthit_miss)]\n")
23437
0
SLANG_RAW("    static void __hlslMakeHit<attr_t>(RaytracingAccelerationStructure AccelerationStructure,\n")
23438
0
SLANG_RAW("        uint InstanceIndex,\n")
23439
0
SLANG_RAW("        uint GeometryIndex,\n")
23440
0
SLANG_RAW("        uint PrimitiveIndex,\n")
23441
0
SLANG_RAW("        uint HitKind,\n")
23442
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
23443
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
23444
0
SLANG_RAW("        RayDesc Ray,\n")
23445
0
SLANG_RAW("        attr_t attributes,\n")
23446
0
SLANG_RAW("        out HitObject hitObj)\n")
23447
0
SLANG_RAW("    {\n")
23448
0
SLANG_RAW("        __target_switch\n")
23449
0
SLANG_RAW("        {\n")
23450
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvMakeHit\";\n")
23451
0
SLANG_RAW("        }\n")
23452
0
SLANG_RAW("    }\n")
23453
0
SLANG_RAW("\n")
23454
0
SLANG_RAW("    [__requiresNVAPI]\n")
23455
0
SLANG_RAW("    [require(hlsl, ser_raygen_closesthit_miss)]\n")
23456
0
SLANG_RAW("    static void __hlslTraceRay<payload_t>(\n")
23457
0
SLANG_RAW("        RaytracingAccelerationStructure AccelerationStructure,\n")
23458
0
SLANG_RAW("        uint RayFlags,\n")
23459
0
SLANG_RAW("        uint InstanceInclusionMask,\n")
23460
0
SLANG_RAW("        uint RayContributionToHitGroupIndex,\n")
23461
0
SLANG_RAW("        uint MultiplierForGeometryContributionToHitGroupIndex,\n")
23462
0
SLANG_RAW("        uint MissShaderIndex,\n")
23463
0
SLANG_RAW("        RayDesc Ray,\n")
23464
0
SLANG_RAW("        inout payload_t Payload,\n")
23465
0
SLANG_RAW("        out HitObject hitObj)\n")
23466
0
SLANG_RAW("    {\n")
23467
0
SLANG_RAW("        __target_switch\n")
23468
0
SLANG_RAW("        {\n")
23469
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvTraceRayHitObject\";\n")
23470
0
SLANG_RAW("        }\n")
23471
0
SLANG_RAW("    }\n")
23472
0
SLANG_RAW("\n")
23473
0
SLANG_RAW("    ///\n")
23474
0
SLANG_RAW("    /// !!!! Internal GLSL GL_NV_shader_invocation_reorder impl. Not part of interface! !!!!!!!!!!!!\n")
23475
0
SLANG_RAW("    ///\n")
23476
0
SLANG_RAW("\n")
23477
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23478
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23479
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23480
0
SLANG_RAW("    static void __glslMakeMiss(\n")
23481
0
SLANG_RAW("        out HitObject hitObj,\n")
23482
0
SLANG_RAW("        uint MissShaderIndex,\n")
23483
0
SLANG_RAW("        float3 Origin,\n")
23484
0
SLANG_RAW("        float TMin,\n")
23485
0
SLANG_RAW("        float3 Direction,\n")
23486
0
SLANG_RAW("        float TMax)\n")
23487
0
SLANG_RAW("    {\n")
23488
0
SLANG_RAW("        __target_switch\n")
23489
0
SLANG_RAW("        {\n")
23490
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordMissNV\";\n")
23491
0
SLANG_RAW("        }\n")
23492
0
SLANG_RAW("    }\n")
23493
0
SLANG_RAW("\n")
23494
0
SLANG_RAW("    // \"void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);\"\n")
23495
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23496
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23497
0
SLANG_RAW("    __glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
23498
0
SLANG_RAW("    [require(glsl, ser_motion_raygen_closesthit_miss)]\n")
23499
0
SLANG_RAW("    static void __glslMakeMotionMiss(\n")
23500
0
SLANG_RAW("        out HitObject hitObj,\n")
23501
0
SLANG_RAW("        uint MissShaderIndex,\n")
23502
0
SLANG_RAW("        float3 Origin,\n")
23503
0
SLANG_RAW("        float TMin,\n")
23504
0
SLANG_RAW("        float3 Direction,\n")
23505
0
SLANG_RAW("        float TMax,\n")
23506
0
SLANG_RAW("        float CurrentTime)\n")
23507
0
SLANG_RAW("    {\n")
23508
0
SLANG_RAW("        __target_switch\n")
23509
0
SLANG_RAW("        {\n")
23510
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordMissMotionNV\";\n")
23511
0
SLANG_RAW("        }\n")
23512
0
SLANG_RAW("    }\n")
23513
0
SLANG_RAW("\n")
23514
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23515
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23516
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23517
0
SLANG_RAW("    static void __glslMakeNop(out HitObject hitObj)\n")
23518
0
SLANG_RAW("    {\n")
23519
0
SLANG_RAW("        __target_switch\n")
23520
0
SLANG_RAW("        {\n")
23521
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordEmptyNV\";\n")
23522
0
SLANG_RAW("        }\n")
23523
0
SLANG_RAW("    }\n")
23524
0
SLANG_RAW("\n")
23525
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23526
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23527
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23528
0
SLANG_RAW("    float3 __glslGetRayDirection()\n")
23529
0
SLANG_RAW("    {\n")
23530
0
SLANG_RAW("        __target_switch\n")
23531
0
SLANG_RAW("        {\n")
23532
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetObjectRayDirectionNV($0)\";\n")
23533
0
SLANG_RAW("        }\n")
23534
0
SLANG_RAW("    }\n")
23535
0
SLANG_RAW("\n")
23536
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23537
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23538
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23539
0
SLANG_RAW("    float3 __glslGetRayWorldDirection()\n")
23540
0
SLANG_RAW("    {\n")
23541
0
SLANG_RAW("        __target_switch\n")
23542
0
SLANG_RAW("        {\n")
23543
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetWorldRayDirectionNV($0)\";\n")
23544
0
SLANG_RAW("        }\n")
23545
0
SLANG_RAW("    }\n")
23546
0
SLANG_RAW("\n")
23547
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23548
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23549
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23550
0
SLANG_RAW("    float3 __glslGetRayWorldOrigin()\n")
23551
0
SLANG_RAW("    {\n")
23552
0
SLANG_RAW("        __target_switch\n")
23553
0
SLANG_RAW("        {\n")
23554
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetWorldRayOriginNV($0)\";\n")
23555
0
SLANG_RAW("        }\n")
23556
0
SLANG_RAW("    }\n")
23557
0
SLANG_RAW("\n")
23558
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23559
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23560
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23561
0
SLANG_RAW("    float __glslGetTMax()\n")
23562
0
SLANG_RAW("    {\n")
23563
0
SLANG_RAW("        __target_switch\n")
23564
0
SLANG_RAW("        {\n")
23565
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetRayTMaxNV($0)\";\n")
23566
0
SLANG_RAW("        }\n")
23567
0
SLANG_RAW("    }\n")
23568
0
SLANG_RAW("\n")
23569
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23570
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23571
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23572
0
SLANG_RAW("    float __glslGetTMin()\n")
23573
0
SLANG_RAW("    {\n")
23574
0
SLANG_RAW("        __target_switch\n")
23575
0
SLANG_RAW("        {\n")
23576
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetRayTMinNV($0)\";\n")
23577
0
SLANG_RAW("        }\n")
23578
0
SLANG_RAW("    }\n")
23579
0
SLANG_RAW("\n")
23580
0
SLANG_RAW("    // \"void hitObjectRecordHitWithIndexNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);\"\n")
23581
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23582
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23583
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23584
0
SLANG_RAW("    static void __glslMakeHitWithIndex(\n")
23585
0
SLANG_RAW("        out HitObject hitObj,\n")
23586
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23587
0
SLANG_RAW("        int instanceid,\n")
23588
0
SLANG_RAW("        int primitiveid,\n")
23589
0
SLANG_RAW("        int geometryindex,\n")
23590
0
SLANG_RAW("        uint hitKind,\n")
23591
0
SLANG_RAW("        uint sbtRecordIndex,\n")
23592
0
SLANG_RAW("        float3 origin,\n")
23593
0
SLANG_RAW("        float Tmin,\n")
23594
0
SLANG_RAW("        float3 direction,\n")
23595
0
SLANG_RAW("        float Tmax,\n")
23596
0
SLANG_RAW("        int attributeLocation)\n")
23597
0
SLANG_RAW("    {\n")
23598
0
SLANG_RAW("        __target_switch\n")
23599
0
SLANG_RAW("        {\n")
23600
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordHitWithIndexNV\";\n")
23601
0
SLANG_RAW("        }\n")
23602
0
SLANG_RAW("    }\n")
23603
0
SLANG_RAW("\n")
23604
0
SLANG_RAW("    //  \"void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);\"\n")
23605
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23606
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23607
0
SLANG_RAW("    __glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
23608
0
SLANG_RAW("    [require(glsl, ser_motion_raygen_closesthit_miss)]\n")
23609
0
SLANG_RAW("    static void __glslMakeMotionHitWithIndex(\n")
23610
0
SLANG_RAW("        out HitObject hitObj,\n")
23611
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23612
0
SLANG_RAW("        int instanceid,\n")
23613
0
SLANG_RAW("        int primitiveid,\n")
23614
0
SLANG_RAW("        int geometryindex,\n")
23615
0
SLANG_RAW("        uint hitKind,\n")
23616
0
SLANG_RAW("        uint sbtRecordIndex,\n")
23617
0
SLANG_RAW("        float3 origin,\n")
23618
0
SLANG_RAW("        float Tmin,\n")
23619
0
SLANG_RAW("        float3 direction,\n")
23620
0
SLANG_RAW("        float Tmax,\n")
23621
0
SLANG_RAW("        float CurrentTime,\n")
23622
0
SLANG_RAW("        int attributeLocation)\n")
23623
0
SLANG_RAW("    {\n")
23624
0
SLANG_RAW("        __target_switch\n")
23625
0
SLANG_RAW("        {\n")
23626
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordHitWithIndexMotionNV\";\n")
23627
0
SLANG_RAW("        }\n")
23628
0
SLANG_RAW("    }\n")
23629
0
SLANG_RAW("\n")
23630
0
SLANG_RAW("    // \"void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);\"\n")
23631
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23632
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23633
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23634
0
SLANG_RAW("    static void __glslMakeHit(\n")
23635
0
SLANG_RAW("        out HitObject hitObj,\n")
23636
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23637
0
SLANG_RAW("        int instanceid,\n")
23638
0
SLANG_RAW("        int primitiveid,\n")
23639
0
SLANG_RAW("        int geometryindex,\n")
23640
0
SLANG_RAW("        uint hitKind,\n")
23641
0
SLANG_RAW("        uint sbtRecordOffset,\n")
23642
0
SLANG_RAW("        uint sbtRecordStride,\n")
23643
0
SLANG_RAW("        float3 origin,\n")
23644
0
SLANG_RAW("        float Tmin,\n")
23645
0
SLANG_RAW("        float3 direction,\n")
23646
0
SLANG_RAW("        float Tmax,\n")
23647
0
SLANG_RAW("        int attributeLocation)\n")
23648
0
SLANG_RAW("    {\n")
23649
0
SLANG_RAW("        __target_switch\n")
23650
0
SLANG_RAW("        {\n")
23651
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordHitNV\";\n")
23652
0
SLANG_RAW("        }\n")
23653
0
SLANG_RAW("    }\n")
23654
0
SLANG_RAW("\n")
23655
0
SLANG_RAW("        // \"void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);\"\n")
23656
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23657
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23658
0
SLANG_RAW("    __glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
23659
0
SLANG_RAW("    [require(glsl, ser_motion_raygen_closesthit_miss)]\n")
23660
0
SLANG_RAW("    static void __glslMakeMotionHit(\n")
23661
0
SLANG_RAW("        out HitObject hitObj,\n")
23662
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23663
0
SLANG_RAW("        int instanceid,\n")
23664
0
SLANG_RAW("        int primitiveid,\n")
23665
0
SLANG_RAW("        int geometryindex,\n")
23666
0
SLANG_RAW("        uint hitKind,\n")
23667
0
SLANG_RAW("        uint sbtRecordOffset,\n")
23668
0
SLANG_RAW("        uint sbtRecordStride,\n")
23669
0
SLANG_RAW("        float3 origin,\n")
23670
0
SLANG_RAW("        float Tmin,\n")
23671
0
SLANG_RAW("        float3 direction,\n")
23672
0
SLANG_RAW("        float Tmax,\n")
23673
0
SLANG_RAW("        float CurrentTime,\n")
23674
0
SLANG_RAW("        int attributeLocation)\n")
23675
0
SLANG_RAW("    {\n")
23676
0
SLANG_RAW("        __target_switch\n")
23677
0
SLANG_RAW("        {\n")
23678
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectRecordHitMotionNV\";\n")
23679
0
SLANG_RAW("        }\n")
23680
0
SLANG_RAW("    }\n")
23681
0
SLANG_RAW("\n")
23682
0
SLANG_RAW("\n")
23683
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23684
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23685
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23686
0
SLANG_RAW("    void __glslGetAttributes(int attributeLocation)\n")
23687
0
SLANG_RAW("    {\n")
23688
0
SLANG_RAW("        __target_switch\n")
23689
0
SLANG_RAW("        {\n")
23690
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectGetAttributesNV($0, $1)\";\n")
23691
0
SLANG_RAW("        }\n")
23692
0
SLANG_RAW("    }\n")
23693
0
SLANG_RAW("\n")
23694
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23695
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23696
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23697
0
SLANG_RAW("    static void __glslTraceRay(\n")
23698
0
SLANG_RAW("        out HitObject hitObject,\n")
23699
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23700
0
SLANG_RAW("        uint rayFlags,\n")
23701
0
SLANG_RAW("        uint cullMask,\n")
23702
0
SLANG_RAW("        uint sbtRecordOffset,\n")
23703
0
SLANG_RAW("        uint sbtRecordStride,\n")
23704
0
SLANG_RAW("        uint missIndex,\n")
23705
0
SLANG_RAW("        float3 origin,\n")
23706
0
SLANG_RAW("        float Tmin,\n")
23707
0
SLANG_RAW("        float3 direction,\n")
23708
0
SLANG_RAW("        float Tmax,\n")
23709
0
SLANG_RAW("        int payload)\n")
23710
0
SLANG_RAW("    {\n")
23711
0
SLANG_RAW("        __target_switch\n")
23712
0
SLANG_RAW("        {\n")
23713
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectTraceRayNV\";\n")
23714
0
SLANG_RAW("        }\n")
23715
0
SLANG_RAW("    }\n")
23716
0
SLANG_RAW("\n")
23717
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23718
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23719
0
SLANG_RAW("    __glsl_extension(GL_NV_ray_tracing_motion_blur)\n")
23720
0
SLANG_RAW("    [require(glsl, ser_motion_raygen_closesthit_miss)]\n")
23721
0
SLANG_RAW("    static void __glslTraceMotionRay(\n")
23722
0
SLANG_RAW("        out HitObject hitObject,\n")
23723
0
SLANG_RAW("        RaytracingAccelerationStructure accelerationStructure,\n")
23724
0
SLANG_RAW("        uint rayFlags,\n")
23725
0
SLANG_RAW("        uint cullMask,\n")
23726
0
SLANG_RAW("        uint sbtRecordOffset,\n")
23727
0
SLANG_RAW("        uint sbtRecordStride,\n")
23728
0
SLANG_RAW("        uint missIndex,\n")
23729
0
SLANG_RAW("        float3 origin,\n")
23730
0
SLANG_RAW("        float Tmin,\n")
23731
0
SLANG_RAW("        float3 direction,\n")
23732
0
SLANG_RAW("        float Tmax,\n")
23733
0
SLANG_RAW("        float currentTime,\n")
23734
0
SLANG_RAW("        int payload)\n")
23735
0
SLANG_RAW("    {\n")
23736
0
SLANG_RAW("        __target_switch\n")
23737
0
SLANG_RAW("        {\n")
23738
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectTraceRayMotionNV\";\n")
23739
0
SLANG_RAW("        }\n")
23740
0
SLANG_RAW("    }\n")
23741
0
SLANG_RAW("\n")
23742
0
SLANG_RAW("    __glsl_extension(GL_EXT_ray_tracing)\n")
23743
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_invocation_reorder)\n")
23744
0
SLANG_RAW("    [require(glsl, ser_raygen_closesthit_miss)]\n")
23745
0
SLANG_RAW("    static void __glslInvoke(\n")
23746
0
SLANG_RAW("        HitObject hitObj,\n")
23747
0
SLANG_RAW("        int payload)\n")
23748
0
SLANG_RAW("    {\n")
23749
0
SLANG_RAW("        __target_switch\n")
23750
0
SLANG_RAW("        {\n")
23751
0
SLANG_RAW("        case glsl: __intrinsic_asm \"hitObjectExecuteShaderNV\";\n")
23752
0
SLANG_RAW("        }\n")
23753
0
SLANG_RAW("    }\n")
23754
0
SLANG_RAW("};\n")
23755
0
SLANG_RAW("\n")
23756
0
SLANG_RAW("    /// Reorders threads based on a coherence hint value. NumCoherenceHintBits indicates how many of\n")
23757
0
SLANG_RAW("    /// the least significant bits of CoherenceHint should be considered during reordering (max: 16).\n")
23758
0
SLANG_RAW("    /// Applications should set this to the lowest value required to represent all possible values in\n")
23759
0
SLANG_RAW("    /// CoherenceHint. For best performance, all threads should provide the same value for\n")
23760
0
SLANG_RAW("    /// NumCoherenceHintBits.\n")
23761
0
SLANG_RAW("    /// Where possible, reordering will also attempt to retain locality in the thread429496726642949671684294967193s launch indices\n")
23762
0
SLANG_RAW("    /// (DispatchRaysIndex in DXR).\n")
23763
0
SLANG_RAW("[__requiresNVAPI]\n")
23764
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
23765
0
SLANG_RAW("__glsl_extension(GL_NV_shader_invocation_reorder)\n")
23766
0
SLANG_RAW("[ForceInline]\n")
23767
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, ser_raygen)]\n")
23768
0
SLANG_RAW("void ReorderThread( uint CoherenceHint, uint NumCoherenceHintBitsFromLSB )\n")
23769
0
SLANG_RAW("{\n")
23770
0
SLANG_RAW("    __target_switch\n")
23771
0
SLANG_RAW("    {\n")
23772
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvReorderThread\";\n")
23773
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reorderThreadNV\";\n")
23774
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixReorder\";\n")
23775
0
SLANG_RAW("    case spirv:\n")
23776
0
SLANG_RAW("        spirv_asm\n")
23777
0
SLANG_RAW("        {\n")
23778
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23779
0
SLANG_RAW("            OpCapability ShaderInvocationReorderNV;\n")
23780
0
SLANG_RAW("            OpReorderThreadWithHintNV $CoherenceHint $NumCoherenceHintBitsFromLSB;\n")
23781
0
SLANG_RAW("        };\n")
23782
0
SLANG_RAW("    }\n")
23783
0
SLANG_RAW("}\n")
23784
0
SLANG_RAW("\n")
23785
0
SLANG_RAW("    /// Reorders threads based on a hit object, optionally extended by a coherence hint value. Coherence\n")
23786
0
SLANG_RAW("    /// hints behave as described in the generic variant of ReorderThread. The maximum number of\n")
23787
0
SLANG_RAW("    /// coherence hint bits in this variant of ReorderThread is 8. If no coherence hint is desired, set\n")
23788
0
SLANG_RAW("    /// NumCoherenceHitBits to zero.\n")
23789
0
SLANG_RAW("    /// Reordering will consider information in the HitObject and coherence hint with the following\n")
23790
0
SLANG_RAW("    /// priority:\n")
23791
0
SLANG_RAW("    ///\n")
23792
0
SLANG_RAW("    /// 1. Shader ID stored in the HitObject\n")
23793
0
SLANG_RAW("    /// 2. Coherence hint, with the most significant hint bit having highest priority\n")
23794
0
SLANG_RAW("    /// 3. Spatial information stored in the HitObject\n")
23795
0
SLANG_RAW("    ///\n")
23796
0
SLANG_RAW("    /// That is, ReorderThread will first attempt to group threads whose HitObject references the\n")
23797
0
SLANG_RAW("    /// same shader ID. (Miss shaders and NOP HitObjects are grouped separately). Within each of these\n")
23798
0
SLANG_RAW("    /// groups, it will attempt to order threads by the value of their coherence hints. And within ranges\n")
23799
0
SLANG_RAW("    /// of equal coherence hints, it will attempt to maximize locality in 3D space of the ray hit (if any).\n")
23800
0
SLANG_RAW("\n")
23801
0
SLANG_RAW("[__requiresNVAPI]\n")
23802
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
23803
0
SLANG_RAW("__glsl_extension(GL_NV_shader_invocation_reorder)\n")
23804
0
SLANG_RAW("[ForceInline]\n")
23805
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, ser_raygen)]\n")
23806
0
SLANG_RAW("void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB )\n")
23807
0
SLANG_RAW("{\n")
23808
0
SLANG_RAW("    __target_switch\n")
23809
0
SLANG_RAW("    {\n")
23810
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvReorderThread\";\n")
23811
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reorderThreadNV\";\n")
23812
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixReorder($1, $2)\";\n")
23813
0
SLANG_RAW("    case spirv:\n")
23814
0
SLANG_RAW("        spirv_asm\n")
23815
0
SLANG_RAW("        {\n")
23816
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23817
0
SLANG_RAW("            OpCapability ShaderInvocationReorderNV;\n")
23818
0
SLANG_RAW("            OpReorderThreadWithHitObjectNV &HitOrMiss $CoherenceHint $NumCoherenceHintBitsFromLSB;\n")
23819
0
SLANG_RAW("        };\n")
23820
0
SLANG_RAW("    }\n")
23821
0
SLANG_RAW("}\n")
23822
0
SLANG_RAW("\n")
23823
0
SLANG_RAW("    // Is equivalent to\n")
23824
0
SLANG_RAW("    // ```\n")
23825
0
SLANG_RAW("    // void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB );\n")
23826
0
SLANG_RAW("    // ```\n")
23827
0
SLANG_RAW("    // With CoherenceHint and NumCoherenceHintBitsFromLSB as 0, meaning they are ignored.\n")
23828
0
SLANG_RAW("\n")
23829
0
SLANG_RAW("[__requiresNVAPI]\n")
23830
0
SLANG_RAW("__glsl_extension(GL_EXT_ray_tracing)\n")
23831
0
SLANG_RAW("__glsl_extension(GL_NV_shader_invocation_reorder)\n")
23832
0
SLANG_RAW("[ForceInline]\n")
23833
0
SLANG_RAW("[require(cuda_glsl_hlsl_spirv, ser_raygen)]\n")
23834
0
SLANG_RAW("void ReorderThread( HitObject HitOrMiss )\n")
23835
0
SLANG_RAW("{\n")
23836
0
SLANG_RAW("    __target_switch\n")
23837
0
SLANG_RAW("    {\n")
23838
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"NvReorderThread\";\n")
23839
0
SLANG_RAW("    case glsl: __intrinsic_asm \"reorderThreadNV\";\n")
23840
0
SLANG_RAW("    case cuda: __intrinsic_asm \"optixReorder()\";\n")
23841
0
SLANG_RAW("    case spirv:\n")
23842
0
SLANG_RAW("        spirv_asm\n")
23843
0
SLANG_RAW("        {\n")
23844
0
SLANG_RAW("            OpExtension \"SPV_NV_shader_invocation_reorder\";\n")
23845
0
SLANG_RAW("            OpCapability ShaderInvocationReorderNV;\n")
23846
0
SLANG_RAW("            OpReorderThreadWithHitObjectNV &HitOrMiss;\n")
23847
0
SLANG_RAW("        };\n")
23848
0
SLANG_RAW("    }\n")
23849
0
SLANG_RAW("}\n")
23850
0
SLANG_RAW("\n")
23851
0
SLANG_RAW("///\n")
23852
0
SLANG_RAW("/// DebugBreak support\n")
23853
0
SLANG_RAW("///\n")
23854
0
SLANG_RAW("/// There doesn't appear to be an equivalent for debugBreak for HLSL\n")
23855
0
SLANG_RAW("\n")
23856
0
SLANG_RAW("[require(glsl)]\n")
23857
0
SLANG_RAW("__specialized_for_target(glsl)\n")
23858
0
SLANG_RAW("[[vk::spirv_instruction(1, \"NonSemantic.DebugBreak\")]]\n")
23859
0
SLANG_RAW("void __glslDebugBreak();\n")
23860
0
SLANG_RAW("\n")
23861
0
SLANG_RAW("[ForceInline]\n")
23862
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl, breakpoint)]\n")
23863
0
SLANG_RAW("void debugBreak()\n")
23864
0
SLANG_RAW("{\n")
23865
0
SLANG_RAW("    __target_switch\n")
23866
0
SLANG_RAW("    {\n")
23867
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"/* debugBreak() not currently supported for HLSL */\";\n")
23868
0
SLANG_RAW("    case cuda: __intrinsic_asm \"__brkpt()\";\n")
23869
0
SLANG_RAW("    case cpp: __intrinsic_asm \"SLANG_BREAKPOINT(0)\";\n")
23870
0
SLANG_RAW("    case glsl:\n")
23871
0
SLANG_RAW("        __glslDebugBreak();\n")
23872
0
SLANG_RAW("        return;\n")
23873
0
SLANG_RAW("    }\n")
23874
0
SLANG_RAW("}\n")
23875
0
SLANG_RAW("\n")
23876
0
SLANG_RAW("\n")
23877
0
SLANG_RAW("//\n")
23878
0
SLANG_RAW("// Realtime Clock support\n")
23879
0
SLANG_RAW("//\n")
23880
0
SLANG_RAW("\n")
23881
0
SLANG_RAW("// https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_realtime_clock.txt\n")
23882
0
SLANG_RAW("\n")
23883
0
SLANG_RAW("[__requiresNVAPI]\n")
23884
0
SLANG_RAW("__glsl_extension(GL_EXT_shader_realtime_clock)\n")
23885
0
SLANG_RAW("[NonUniformReturn]\n")
23886
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shaderclock)]\n")
23887
0
SLANG_RAW("uint getRealtimeClockLow()\n")
23888
0
SLANG_RAW("{\n")
23889
0
SLANG_RAW("    __target_switch\n")
23890
0
SLANG_RAW("    {\n")
23891
0
SLANG_RAW("    case hlsl:\n")
23892
0
SLANG_RAW("        __intrinsic_asm \"NvGetSpecial( NV_SPECIALOP_GLOBAL_TIMER_LO)\";\n")
23893
0
SLANG_RAW("    case glsl:\n")
23894
0
SLANG_RAW("        return getRealtimeClock().x;\n")
23895
0
SLANG_RAW("    case cuda:\n")
23896
0
SLANG_RAW("        __intrinsic_asm \"clock\";\n")
23897
0
SLANG_RAW("    case spirv:\n")
23898
0
SLANG_RAW("        return getRealtimeClock().x;\n")
23899
0
SLANG_RAW("    case cpp:\n")
23900
0
SLANG_RAW("        __intrinsic_asm \"(uint32_t)std::chrono::high_resolution_clock::now().time_since_epoch().count()\";\n")
23901
0
SLANG_RAW("    }\n")
23902
0
SLANG_RAW("}\n")
23903
0
SLANG_RAW("\n")
23904
0
SLANG_RAW("[NonUniformReturn]\n")
23905
0
SLANG_RAW("[require(cpp_cuda, shaderclock)]\n")
23906
0
SLANG_RAW("int64_t __cudaCppGetRealtimeClock()\n")
23907
0
SLANG_RAW("{\n")
23908
0
SLANG_RAW("    __target_switch\n")
23909
0
SLANG_RAW("    {\n")
23910
0
SLANG_RAW("    case cpp: __intrinsic_asm \"std::chrono::high_resolution_clock::now().time_since_epoch().count()\";\n")
23911
0
SLANG_RAW("    case cuda: __intrinsic_asm \"clock64\";\n")
23912
0
SLANG_RAW("    }\n")
23913
0
SLANG_RAW("}\n")
23914
0
SLANG_RAW("\n")
23915
0
SLANG_RAW("[__requiresNVAPI]\n")
23916
0
SLANG_RAW("__glsl_extension(GL_EXT_shader_realtime_clock)\n")
23917
0
SLANG_RAW("[NonUniformReturn]\n")
23918
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_spirv, shaderclock)]\n")
23919
0
SLANG_RAW("uint2 getRealtimeClock()\n")
23920
0
SLANG_RAW("{\n")
23921
0
SLANG_RAW("    __target_switch\n")
23922
0
SLANG_RAW("    {\n")
23923
0
SLANG_RAW("    case hlsl:\n")
23924
0
SLANG_RAW("        __intrinsic_asm \"uint2(NvGetSpecial(NV_SPECIALOP_GLOBAL_TIMER_LO), NvGetSpecial( NV_SPECIALOP_GLOBAL_TIMER_HI))\";\n")
23925
0
SLANG_RAW("    case glsl:\n")
23926
0
SLANG_RAW("        __intrinsic_asm \"clockRealtime2x32EXT()\";\n")
23927
0
SLANG_RAW("    case cuda:\n")
23928
0
SLANG_RAW("    case cpp:\n")
23929
0
SLANG_RAW("        int64_t ticks = __cudaCppGetRealtimeClock();\n")
23930
0
SLANG_RAW("        return uint2(uint(ticks), uint(uint64_t(ticks) >> 32));\n")
23931
0
SLANG_RAW("    case spirv:\n")
23932
0
SLANG_RAW("        return spirv_asm\n")
23933
0
SLANG_RAW("        {\n")
23934
0
SLANG_RAW("            OpCapability ShaderClockKHR;\n")
23935
0
SLANG_RAW("            OpExtension \"SPV_KHR_shader_clock\";\n")
23936
0
SLANG_RAW("            result : $$uint2 = OpReadClockKHR Device\n")
23937
0
SLANG_RAW("        };\n")
23938
0
SLANG_RAW("    }\n")
23939
0
SLANG_RAW("}\n")
23940
0
SLANG_RAW("\n")
23941
0
SLANG_RAW("//\n")
23942
0
SLANG_RAW("// CUDA specific\n")
23943
0
SLANG_RAW("//\n")
23944
0
SLANG_RAW("\n")
23945
0
SLANG_RAW("[__readNone]\n")
23946
0
SLANG_RAW("[NonUniformReturn]\n")
23947
0
SLANG_RAW("[require(cuda)]\n")
23948
0
SLANG_RAW("uint3 cudaThreadIdx()\n")
23949
0
SLANG_RAW("{\n")
23950
0
SLANG_RAW("    __target_switch\n")
23951
0
SLANG_RAW("    {\n")
23952
0
SLANG_RAW("    case cuda: __intrinsic_asm \"(threadIdx)\";\n")
23953
0
SLANG_RAW("    }\n")
23954
0
SLANG_RAW("}\n")
23955
0
SLANG_RAW("\n")
23956
0
SLANG_RAW("[__readNone]\n")
23957
0
SLANG_RAW("[NonUniformReturn]\n")
23958
0
SLANG_RAW("[require(cuda)]\n")
23959
0
SLANG_RAW("uint3 cudaBlockIdx()\n")
23960
0
SLANG_RAW("{\n")
23961
0
SLANG_RAW("    __target_switch\n")
23962
0
SLANG_RAW("    {\n")
23963
0
SLANG_RAW("    case cuda: __intrinsic_asm \"(blockIdx)\";\n")
23964
0
SLANG_RAW("    }\n")
23965
0
SLANG_RAW("}\n")
23966
0
SLANG_RAW("\n")
23967
0
SLANG_RAW("[__readNone]\n")
23968
0
SLANG_RAW("[NonUniformReturn]\n")
23969
0
SLANG_RAW("[require(cuda)]\n")
23970
0
SLANG_RAW("uint3 cudaBlockDim()\n")
23971
0
SLANG_RAW("{\n")
23972
0
SLANG_RAW("    __target_switch\n")
23973
0
SLANG_RAW("    {\n")
23974
0
SLANG_RAW("    case cuda: __intrinsic_asm \"(blockDim)\";\n")
23975
0
SLANG_RAW("    }\n")
23976
0
SLANG_RAW("}\n")
23977
0
SLANG_RAW("\n")
23978
0
SLANG_RAW("//\n")
23979
0
SLANG_RAW("// Workgroup cooperation\n")
23980
0
SLANG_RAW("//\n")
23981
0
SLANG_RAW("\n")
23982
0
SLANG_RAW("//\n")
23983
0
SLANG_RAW("// `saturated_cooperation(c, f, s, u)` will call `f(s, u)` if not all lanes in the\n")
23984
0
SLANG_RAW("// workgroup are currently executing. however if all lanes are saturated, then\n")
23985
0
SLANG_RAW("// for each unique `s` across all the active lanes `c(s, u)` is called. The\n")
23986
0
SLANG_RAW("// return value is the one corresponding to the input `s` from this lane.\n")
23987
0
SLANG_RAW("//\n")
23988
0
SLANG_RAW("// Adjacent calls to saturated_cooperation are subject to fusion, i.e.\n")
23989
0
SLANG_RAW("//      saturated_cooperation(c1, f1, s, u1);\n")
23990
0
SLANG_RAW("//      saturated_cooperation(c2, f2, s, u2);\n")
23991
0
SLANG_RAW("// will be transformed to:\n")
23992
0
SLANG_RAW("//      saturated_cooperation(c1c2, f1f2, s, u1u2);\n")
23993
0
SLANG_RAW("// where\n")
23994
0
SLANG_RAW("//      c1c2 is a function which calls c1(s, u1) and then c2(s, u2);\n")
23995
0
SLANG_RAW("//      f1f2 is a function which calls f1(s, u1) and then f2(s, u2);\n")
23996
0
SLANG_RAW("//\n")
23997
0
SLANG_RAW("// When the input differs, calls are fused\n")
23998
0
SLANG_RAW("//      saturated_cooperation(c1, f1, s1, u1);\n")
23999
0
SLANG_RAW("//      saturated_cooperation(c2, f2, s2, u2);\n")
24000
0
SLANG_RAW("// will be transformed to:\n")
24001
0
SLANG_RAW("//      saturated_cooperation(c1c2, f1f2, s1s2, u1u2);\n")
24002
0
SLANG_RAW("// where\n")
24003
0
SLANG_RAW("//      s1s2 is a tuple of s1 and s2\n")
24004
0
SLANG_RAW("//      c1c2 is a function which calls c1(s1, u1) and then c2(s2, u2);\n")
24005
0
SLANG_RAW("//      f1f2 is a function which calls f1(s1, u1) and then f2(s2, u2);\n")
24006
0
SLANG_RAW("// Note that in this case, we will make a call to c1c2 for every unique pair\n")
24007
0
SLANG_RAW("// s1s2 across all lanes\n")
24008
0
SLANG_RAW("//\n")
24009
0
SLANG_RAW("// (This fusion takes place in the fuse-satcoop pass, and as such any changes to\n")
24010
0
SLANG_RAW("// the signature or behavior of this function should be adjusted for there).\n")
24011
0
SLANG_RAW("//\n")
24012
0
SLANG_RAW("//@hidden:\n")
24013
0
SLANG_RAW("[KnownBuiltin(")
24014
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::saturated_cooperation
24015
0
)
24016
0
SLANG_RAW(")]\n")
24017
0
SLANG_RAW("func saturated_cooperation<A : __BuiltinType, B, C>(\n")
24018
0
SLANG_RAW("    cooperate : functype (A, B) -> C,\n")
24019
0
SLANG_RAW("    fallback : functype (A, B) -> C,\n")
24020
0
SLANG_RAW("    A input,\n")
24021
0
SLANG_RAW("    B otherArg)\n")
24022
0
SLANG_RAW("    -> C\n")
24023
0
SLANG_RAW("{\n")
24024
0
SLANG_RAW("    return saturated_cooperation_using(cooperate, fallback, __WaveMatchBuitin<A>, __WaveReadLaneAtBuiltin<A>, input, otherArg);\n")
24025
0
SLANG_RAW("}\n")
24026
0
SLANG_RAW("\n")
24027
0
SLANG_RAW("// These two functions are a temporary (circa May 2023) workaround to the fact\n")
24028
0
SLANG_RAW("// that we can't deduce which overload to pass to saturated_cooperation_using\n")
24029
0
SLANG_RAW("// in the call above\n")
24030
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
24031
0
SLANG_RAW("func __WaveMatchBuitin<T : __BuiltinType>(T t) -> uint4\n")
24032
0
SLANG_RAW("{\n")
24033
0
SLANG_RAW("    return WaveMatch(t);\n")
24034
0
SLANG_RAW("}\n")
24035
0
SLANG_RAW("[__unsafeForceInlineEarly]\n")
24036
0
SLANG_RAW("func __WaveReadLaneAtBuiltin<T : __BuiltinType>(T t, int i) -> T\n")
24037
0
SLANG_RAW("{\n")
24038
0
SLANG_RAW("    return WaveReadLaneAt(t, i);\n")
24039
0
SLANG_RAW("}\n")
24040
0
SLANG_RAW("\n")
24041
0
SLANG_RAW("//\n")
24042
0
SLANG_RAW("// saturated_cooperation, but you're able to specify manually the functions:\n")
24043
0
SLANG_RAW("//\n")
24044
0
SLANG_RAW("// waveMatch: a function to return a mask of lanes with the same input as this one\n")
24045
0
SLANG_RAW("// broadcast: a function which returns the value passed into it on the specified lane\n")
24046
0
SLANG_RAW("//\n")
24047
0
SLANG_RAW("[KnownBuiltin(")
24048
0
SLANG_SPLICE( (int)KnownBuiltinDeclName::saturated_cooperation_using
24049
0
)
24050
0
SLANG_RAW(")]\n")
24051
0
SLANG_RAW("func saturated_cooperation_using<A, B, C>(\n")
24052
0
SLANG_RAW("    cooperate : functype (A, B) -> C,\n")
24053
0
SLANG_RAW("    fallback : functype (A, B) -> C,\n")
24054
0
SLANG_RAW("    waveMatch : functype (A) -> uint4,\n")
24055
0
SLANG_RAW("    broadcast : functype (A, int) -> A,\n")
24056
0
SLANG_RAW("    A input,\n")
24057
0
SLANG_RAW("    B otherArg)\n")
24058
0
SLANG_RAW("    -> C\n")
24059
0
SLANG_RAW("{\n")
24060
0
SLANG_RAW("    const bool isWaveSaturated = WaveActiveCountBits(true) == WaveGetLaneCount();\n")
24061
0
SLANG_RAW("    if(isWaveSaturated)\n")
24062
0
SLANG_RAW("    {\n")
24063
0
SLANG_RAW("        let lanesWithSameInput = waveMatch(input).x;\n")
24064
0
SLANG_RAW("        // Keep least significant lane in our set\n")
24065
0
SLANG_RAW("        let ourRepresentative = lanesWithSameInput & -lanesWithSameInput;\n")
24066
0
SLANG_RAW("        // The representative lanes for all lanes\n")
24067
0
SLANG_RAW("        var allRepresentatives = WaveActiveBitOr(ourRepresentative);\n")
24068
0
SLANG_RAW("\n")
24069
0
SLANG_RAW("        C ret;\n")
24070
0
SLANG_RAW("\n")
24071
0
SLANG_RAW("        // Iterate over set bits in mask from low to high.\n")
24072
0
SLANG_RAW("        // In each iteration the lowest bit is cleared.\n")
24073
0
SLANG_RAW("        while(bool(allRepresentatives))\n")
24074
0
SLANG_RAW("        {\n")
24075
0
SLANG_RAW("            // Broadcast input across warp.\n")
24076
0
SLANG_RAW("            let laneIdx = firstbitlow(allRepresentatives);\n")
24077
0
SLANG_RAW("            let uniformInput = broadcast(input, int(laneIdx));\n")
24078
0
SLANG_RAW("\n")
24079
0
SLANG_RAW("            // All lanes perform some cooperative computation with dynamic\n")
24080
0
SLANG_RAW("            // uniform input\n")
24081
0
SLANG_RAW("            C c = cooperate(uniformInput, otherArg);\n")
24082
0
SLANG_RAW("\n")
24083
0
SLANG_RAW("            // Update our return value until it\n")
24084
0
SLANG_RAW("            if(bool(allRepresentatives & ourRepresentative))\n")
24085
0
SLANG_RAW("                ret = c;\n")
24086
0
SLANG_RAW("\n")
24087
0
SLANG_RAW("            // Clear the lowest bit\n")
24088
0
SLANG_RAW("            allRepresentatives &= allRepresentatives - 1;\n")
24089
0
SLANG_RAW("        }\n")
24090
0
SLANG_RAW("\n")
24091
0
SLANG_RAW("        return ret;\n")
24092
0
SLANG_RAW("    }\n")
24093
0
SLANG_RAW("    else\n")
24094
0
SLANG_RAW("    {\n")
24095
0
SLANG_RAW("        return fallback(input, otherArg);\n")
24096
0
SLANG_RAW("    }\n")
24097
0
SLANG_RAW("}\n")
24098
0
SLANG_RAW("\n")
24099
0
SLANG_RAW("\n")
24100
24101
// The NVAPI operations are defined to take the space/register
24102
// indices of their texture and sampler parameters, rather than
24103
// taking the texture/sampler objects directly.
24104
//
24105
// In order to support this approach, we need intrinsics that
24106
// can magically fetch the binding information for a resource.
24107
//
24108
// TODO: These operations are kind of *screaming* for us to
24109
// have a built-in `interface` that all of the opaque resource
24110
// types conform to, so that we can define builtins that work
24111
// for any resource type.
24112
0
SLANG_RAW("#line 21938 \"hlsl.meta.slang\"")
24113
0
SLANG_RAW("\n")
24114
0
SLANG_RAW("\n")
24115
0
SLANG_RAW("__intrinsic_op(")
24116
0
SLANG_SPLICE(kIROp_GetRegisterSpace
24117
0
)
24118
0
SLANG_RAW(") uint __getRegisterSpace<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>(_Texture<T,Shape,isArray,isMS,sampleCount,access,isShadow,isCombined,format> texture);\n")
24119
0
SLANG_RAW("__intrinsic_op(")
24120
0
SLANG_SPLICE(kIROp_GetRegisterSpace
24121
0
)
24122
0
SLANG_RAW(") uint __getRegisterSpace(SamplerState sampler);\n")
24123
0
SLANG_RAW("\n")
24124
0
SLANG_RAW("__intrinsic_op(")
24125
0
SLANG_SPLICE(kIROp_GetRegisterIndex
24126
0
)
24127
0
SLANG_RAW(") uint __getRegisterIndex<T:ITexelElement, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>(_Texture<T,Shape,isArray,isMS,sampleCount,access,isShadow,isCombined,format> texture);\n")
24128
0
SLANG_RAW("__intrinsic_op(")
24129
0
SLANG_SPLICE(kIROp_GetRegisterIndex
24130
0
)
24131
0
SLANG_RAW(") uint __getRegisterIndex(SamplerState sampler);\n")
24132
0
SLANG_RAW("\n")
24133
0
SLANG_RAW("//@public:\n")
24134
0
SLANG_RAW("\n")
24135
24136
//
24137
// Texture Footprint Queries
24138
//
24139
// This section introduces the types and methods related
24140
// to the `GL_NV_shader_texture_footprint` GLSL extension,
24141
// and the matching NVAPI operations.
24142
//
24143
// Footprint queries are allowed on both 2D and 3D textures,
24144
// and are structurally similar for the two, so we will
24145
// use a meta-loop to deduplicate the code for the two
24146
// cases.
24147
//
24148
24149
// A footprint query yields a data structure
24150
// that describes blocks of texels that
24151
// conservatively cover the data that might
24152
// be fetched in the query.
24153
//
24154
// A given sampling operation might access two
24155
// mip levels of a texture when, e.g., trilinear
24156
// filtering is on. A footprint query may ask for
24157
// a footprint in either the coarse or fine level
24158
// of the pair.
24159
//
24160
// We first define a `struct` type that closely maps
24161
// to how a footprint is defined for each of the
24162
// implementations we support, and then wrap that
24163
// in a derived `struct` that includes the extra
24164
// data that is returned by the GLSL API via the
24165
// function reuslt.
24166
//
24167
0
SLANG_RAW("#line 21980 \"hlsl.meta.slang\"")
24168
0
SLANG_RAW("\n")
24169
0
SLANG_RAW("\n")
24170
0
SLANG_RAW("[__NoSideEffect]\n")
24171
0
SLANG_RAW("[__requiresNVAPI]\n")
24172
0
SLANG_RAW("[require(glsl_hlsl_spirv, texturefootprint)]\n")
24173
0
SLANG_RAW("vector<uint, ND> __textureFootprintGetAnchor<let ND:int>(__TextureFootprintData<ND> data, int nd)\n")
24174
0
SLANG_RAW("{\n")
24175
0
SLANG_RAW("    __target_switch\n")
24176
0
SLANG_RAW("    {\n")
24177
0
SLANG_RAW("    case hlsl:\n")
24178
0
SLANG_RAW("        __intrinsic_asm \"NvFootprintExtractAnchorTileLoc$!1D($0)\";\n")
24179
0
SLANG_RAW("    case glsl:\n")
24180
0
SLANG_RAW("        __intrinsic_asm \"$0.anchor\";\n")
24181
0
SLANG_RAW("    case spirv:\n")
24182
0
SLANG_RAW("        return spirv_asm {\n")
24183
0
SLANG_RAW("            result:$$vector<uint,ND> = OpCompositeExtract $data 1;\n")
24184
0
SLANG_RAW("        };\n")
24185
0
SLANG_RAW("    }\n")
24186
0
SLANG_RAW("}\n")
24187
0
SLANG_RAW("\n")
24188
0
SLANG_RAW("[__NoSideEffect]\n")
24189
0
SLANG_RAW("[__requiresNVAPI]\n")
24190
0
SLANG_RAW("[require(glsl_hlsl_spirv, texturefootprint)]\n")
24191
0
SLANG_RAW("vector<uint, ND> __textureFootprintGetOffset<let ND:int>(__TextureFootprintData<ND> data, int nd)\n")
24192
0
SLANG_RAW("{\n")
24193
0
SLANG_RAW("    __target_switch\n")
24194
0
SLANG_RAW("    {\n")
24195
0
SLANG_RAW("    case hlsl:\n")
24196
0
SLANG_RAW("        __intrinsic_asm \"NvFootprintExtractOffset$!1D($0)\";\n")
24197
0
SLANG_RAW("    case glsl:\n")
24198
0
SLANG_RAW("        __intrinsic_asm \"$0.offset\";\n")
24199
0
SLANG_RAW("    case spirv:\n")
24200
0
SLANG_RAW("        return spirv_asm {\n")
24201
0
SLANG_RAW("            result:$$vector<uint,ND> = OpCompositeExtract $data 2;\n")
24202
0
SLANG_RAW("        };\n")
24203
0
SLANG_RAW("    }\n")
24204
0
SLANG_RAW("}\n")
24205
0
SLANG_RAW("\n")
24206
0
SLANG_RAW("//@public:\n")
24207
0
SLANG_RAW("__intrinsic_type(")
24208
0
SLANG_SPLICE(kIROp_TextureFootprintType
24209
0
)
24210
0
SLANG_RAW(")\n")
24211
0
SLANG_RAW("[require(glsl_hlsl_spirv, texturefootprint)]\n")
24212
0
SLANG_RAW("struct __TextureFootprintData<let ND:int>\n")
24213
0
SLANG_RAW("{\n")
24214
0
SLANG_RAW("    typealias Anchor        = vector<uint, ND>;\n")
24215
0
SLANG_RAW("    typealias Offset        = vector<uint, ND>;\n")
24216
0
SLANG_RAW("    typealias Mask          = uint2;\n")
24217
0
SLANG_RAW("    typealias LOD           = uint;\n")
24218
0
SLANG_RAW("    typealias Granularity   = uint;\n")
24219
0
SLANG_RAW("\n")
24220
0
SLANG_RAW("    property anchor : Anchor\n")
24221
0
SLANG_RAW("    {\n")
24222
0
SLANG_RAW("        [__NoSideEffect]\n")
24223
0
SLANG_RAW("        [__requiresNVAPI]\n")
24224
0
SLANG_RAW("        [ForceInline]\n")
24225
0
SLANG_RAW("        get { return __textureFootprintGetAnchor(this, ND); }\n")
24226
0
SLANG_RAW("    }\n")
24227
0
SLANG_RAW("\n")
24228
0
SLANG_RAW("    property offset : Offset\n")
24229
0
SLANG_RAW("    {\n")
24230
0
SLANG_RAW("        [__NoSideEffect]\n")
24231
0
SLANG_RAW("        [__requiresNVAPI]\n")
24232
0
SLANG_RAW("        [ForceInline]\n")
24233
0
SLANG_RAW("        get { return __textureFootprintGetOffset(this, ND); }\n")
24234
0
SLANG_RAW("    }\n")
24235
0
SLANG_RAW("\n")
24236
0
SLANG_RAW("    property mask : Mask\n")
24237
0
SLANG_RAW("    {\n")
24238
0
SLANG_RAW("        [__NoSideEffect]\n")
24239
0
SLANG_RAW("        [__requiresNVAPI]\n")
24240
0
SLANG_RAW("        get\n")
24241
0
SLANG_RAW("        {\n")
24242
0
SLANG_RAW("            __target_switch\n")
24243
0
SLANG_RAW("            {\n")
24244
0
SLANG_RAW("            case hlsl:\n")
24245
0
SLANG_RAW("                __intrinsic_asm \"NvFootprintExtractBitmask\";\n")
24246
0
SLANG_RAW("            case glsl:\n")
24247
0
SLANG_RAW("                __intrinsic_asm \"$0.mask\";\n")
24248
0
SLANG_RAW("            case spirv:\n")
24249
0
SLANG_RAW("                return spirv_asm {\n")
24250
0
SLANG_RAW("                    result:$$Mask = OpCompositeExtract $this 3;\n")
24251
0
SLANG_RAW("                };\n")
24252
0
SLANG_RAW("            }\n")
24253
0
SLANG_RAW("        }\n")
24254
0
SLANG_RAW("    }\n")
24255
0
SLANG_RAW("\n")
24256
0
SLANG_RAW("    property lod : LOD\n")
24257
0
SLANG_RAW("    {\n")
24258
0
SLANG_RAW("        [__NoSideEffect]\n")
24259
0
SLANG_RAW("        [__requiresNVAPI]\n")
24260
0
SLANG_RAW("        get\n")
24261
0
SLANG_RAW("        {\n")
24262
0
SLANG_RAW("            __target_switch\n")
24263
0
SLANG_RAW("            {\n")
24264
0
SLANG_RAW("            case hlsl:\n")
24265
0
SLANG_RAW("                __intrinsic_asm \"NvFootprintExtractLOD\";\n")
24266
0
SLANG_RAW("            case glsl:\n")
24267
0
SLANG_RAW("                __intrinsic_asm \"$0.lod\";\n")
24268
0
SLANG_RAW("            case spirv:\n")
24269
0
SLANG_RAW("                return spirv_asm {\n")
24270
0
SLANG_RAW("                    result:$$LOD = OpCompositeExtract $this 4;\n")
24271
0
SLANG_RAW("                };\n")
24272
0
SLANG_RAW("            }\n")
24273
0
SLANG_RAW("        }\n")
24274
0
SLANG_RAW("    }\n")
24275
0
SLANG_RAW("\n")
24276
0
SLANG_RAW("    property granularity : Granularity\n")
24277
0
SLANG_RAW("    {\n")
24278
0
SLANG_RAW("        [__NoSideEffect]\n")
24279
0
SLANG_RAW("        [__requiresNVAPI]\n")
24280
0
SLANG_RAW("        get\n")
24281
0
SLANG_RAW("        {\n")
24282
0
SLANG_RAW("            __target_switch\n")
24283
0
SLANG_RAW("            {\n")
24284
0
SLANG_RAW("            case hlsl:\n")
24285
0
SLANG_RAW("                __intrinsic_asm \"NvFootprintExtractReturnGran\";\n")
24286
0
SLANG_RAW("            case glsl:\n")
24287
0
SLANG_RAW("                __intrinsic_asm \"$0.granularity\";\n")
24288
0
SLANG_RAW("            case spirv:\n")
24289
0
SLANG_RAW("                return spirv_asm {\n")
24290
0
SLANG_RAW("                    result:$$Granularity = OpCompositeExtract $this 5;\n")
24291
0
SLANG_RAW("                };\n")
24292
0
SLANG_RAW("            }\n")
24293
0
SLANG_RAW("        }\n")
24294
0
SLANG_RAW("    }\n")
24295
0
SLANG_RAW("}\n")
24296
0
SLANG_RAW("\n")
24297
0
SLANG_RAW("///@category stage_io\n")
24298
0
SLANG_RAW("struct TextureFootprint<let ND:int> : __TextureFootprintData<ND>\n")
24299
0
SLANG_RAW("{\n")
24300
0
SLANG_RAW("    bool _isSingleLevel;\n")
24301
0
SLANG_RAW("\n")
24302
0
SLANG_RAW("    property isSingleLevel : bool\n")
24303
0
SLANG_RAW("    {\n")
24304
0
SLANG_RAW("        [__NoSideEffect]\n")
24305
0
SLANG_RAW("        get\n")
24306
0
SLANG_RAW("        {\n")
24307
0
SLANG_RAW("            return _isSingleLevel;\n")
24308
0
SLANG_RAW("        }\n")
24309
0
SLANG_RAW("    }\n")
24310
0
SLANG_RAW("}\n")
24311
0
SLANG_RAW("\n")
24312
0
SLANG_RAW("///@category stage_io\n")
24313
0
SLANG_RAW("typealias TextureFootprint2D = TextureFootprint<2>;\n")
24314
0
SLANG_RAW("\n")
24315
0
SLANG_RAW("///@category stage_io\n")
24316
0
SLANG_RAW("typealias TextureFootprint3D = TextureFootprint<3>;\n")
24317
0
SLANG_RAW("\n")
24318
24319
// We define the new operations via an `extension`
24320
// on the relevant texture type(s), rather than
24321
// further clutter the original type declarations.
24322
0
SLANG_RAW("#line 22131 \"hlsl.meta.slang\"")
24323
0
SLANG_RAW("\n")
24324
0
SLANG_RAW("\n")
24325
0
SLANG_RAW("__generic<T:ITexelElement, Shape: __ITextureShape, let sampleCount:int, let isShadow:int, let format:int>\n")
24326
0
SLANG_RAW("extension _Texture<T,Shape,0,0,sampleCount,0,isShadow,0,format>\n")
24327
0
SLANG_RAW("{\n")
24328
24329
// We introduce a few convenience type aliases here,
24330
// which both keep our declarations simpler and easier
24331
// to understand, but which might *also* be useful to
24332
// users of the standard module, so that they can write things
24333
// like `Texture2D.Footprint`, and also have auto-complete
24334
// help them find such members.
24335
//
24336
// TODO: The `Coords` type really ought to be something
24337
// defined on the base texture types, rather than via
24338
// this `extension`.
24339
0
SLANG_RAW("#line 22147 \"hlsl.meta.slang\"")
24340
0
SLANG_RAW("\n")
24341
0
SLANG_RAW("    typealias Coords = vector<float, Shape.dimensions>;\n")
24342
0
SLANG_RAW("    typealias Footprint = TextureFootprint<Shape.dimensions>;\n")
24343
0
SLANG_RAW("    typealias __FootprintData = __TextureFootprintData<Shape.dimensions>;\n")
24344
0
SLANG_RAW("    typealias FootprintGranularity = Footprint.Granularity;\n")
24345
0
SLANG_RAW("\n")
24346
24347
// For the GLSL extension, the choice between the
24348
// coarse and fine level is modeled as a `bool`
24349
// parameter to the query operation(s). We define
24350
// the GLSL functions here as intrinsics, so that
24351
// we can refer to them later in the definitions
24352
// of our standard module operaitons; not just in glsl module.
24353
//
24354
// Note: despite the GLSL extension defining the `granularity`
24355
// member of the query result as having type `uint`, the
24356
// function signatures all take `int` parameters for the
24357
// granularity instead.
24358
//
24359
0
SLANG_RAW("#line 22166 \"hlsl.meta.slang\"")
24360
0
SLANG_RAW("\n")
24361
0
SLANG_RAW("\n")
24362
0
SLANG_RAW("    [__NoSideEffect]\n")
24363
0
SLANG_RAW("    __glsl_version(450)\n")
24364
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24365
0
SLANG_RAW("    [require(glsl_spirv, texturefootprint)]\n")
24366
0
SLANG_RAW("    bool __queryFootprintGLSL(\n")
24367
0
SLANG_RAW("            SamplerState    sampler,\n")
24368
0
SLANG_RAW("            Coords          coords,\n")
24369
0
SLANG_RAW("            int             granularity,\n")
24370
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24371
0
SLANG_RAW("            out __FootprintData footprint)\n")
24372
0
SLANG_RAW("    {\n")
24373
0
SLANG_RAW("        __target_switch\n")
24374
0
SLANG_RAW("        {\n")
24375
0
SLANG_RAW("        case glsl:\n")
24376
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintNV($p, $*2)\";\n")
24377
0
SLANG_RAW("        case spirv:\n")
24378
0
SLANG_RAW("            return spirv_asm {\n")
24379
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24380
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24381
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24382
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel;\n")
24383
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24384
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24385
0
SLANG_RAW("            };\n")
24386
0
SLANG_RAW("        }\n")
24387
0
SLANG_RAW("    }\n")
24388
0
SLANG_RAW("\n")
24389
0
SLANG_RAW("    [__NoSideEffect]\n")
24390
0
SLANG_RAW("    __glsl_version(450)\n")
24391
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24392
0
SLANG_RAW("    [require(glsl_spirv, texturefootprint)]\n")
24393
0
SLANG_RAW("    bool __queryFootprintGLSL(\n")
24394
0
SLANG_RAW("            SamplerState    sampler,\n")
24395
0
SLANG_RAW("            Coords          coords,\n")
24396
0
SLANG_RAW("            int             granularity,\n")
24397
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24398
0
SLANG_RAW("            out __FootprintData footprint,\n")
24399
0
SLANG_RAW("            float           bias)\n")
24400
0
SLANG_RAW("    {\n")
24401
0
SLANG_RAW("        __target_switch\n")
24402
0
SLANG_RAW("        {\n")
24403
0
SLANG_RAW("        case glsl:\n")
24404
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintNV($p, $*2)\";\n")
24405
0
SLANG_RAW("        case spirv:\n")
24406
0
SLANG_RAW("            return spirv_asm {\n")
24407
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24408
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24409
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24410
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel Bias $bias;\n")
24411
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24412
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24413
0
SLANG_RAW("            };\n")
24414
0
SLANG_RAW("        }\n")
24415
0
SLANG_RAW("    }\n")
24416
0
SLANG_RAW("\n")
24417
0
SLANG_RAW("    [__NoSideEffect]\n")
24418
0
SLANG_RAW("    __glsl_version(450)\n")
24419
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24420
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
24421
0
SLANG_RAW("    [require(glsl_spirv, texturefootprintclamp)]\n")
24422
0
SLANG_RAW("    bool __queryFootprintClampGLSL(\n")
24423
0
SLANG_RAW("            SamplerState    sampler,\n")
24424
0
SLANG_RAW("            Coords          coords,\n")
24425
0
SLANG_RAW("            float           lodClamp,\n")
24426
0
SLANG_RAW("            int             granularity,\n")
24427
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24428
0
SLANG_RAW("            out __FootprintData footprint)\n")
24429
0
SLANG_RAW("    {\n")
24430
0
SLANG_RAW("        __target_switch\n")
24431
0
SLANG_RAW("        {\n")
24432
0
SLANG_RAW("        case glsl:\n")
24433
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintClampNV($p, $*2)\";\n")
24434
0
SLANG_RAW("        case spirv:\n")
24435
0
SLANG_RAW("            return spirv_asm {\n")
24436
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24437
0
SLANG_RAW("                OpCapability MinLod;\n")
24438
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24439
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24440
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel MinLod $lodClamp;\n")
24441
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24442
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24443
0
SLANG_RAW("            };\n")
24444
0
SLANG_RAW("        }\n")
24445
0
SLANG_RAW("    }\n")
24446
0
SLANG_RAW("\n")
24447
0
SLANG_RAW("    [__NoSideEffect]\n")
24448
0
SLANG_RAW("    __glsl_version(450)\n")
24449
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24450
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
24451
0
SLANG_RAW("    [require(glsl_spirv, texturefootprintclamp)]\n")
24452
0
SLANG_RAW("    bool __queryFootprintClampGLSL(\n")
24453
0
SLANG_RAW("            SamplerState    sampler,\n")
24454
0
SLANG_RAW("            Coords          coords,\n")
24455
0
SLANG_RAW("            float           lodClamp,\n")
24456
0
SLANG_RAW("            int             granularity,\n")
24457
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24458
0
SLANG_RAW("            out __FootprintData footprint,\n")
24459
0
SLANG_RAW("            float           bias)\n")
24460
0
SLANG_RAW("    {\n")
24461
0
SLANG_RAW("        __target_switch\n")
24462
0
SLANG_RAW("        {\n")
24463
0
SLANG_RAW("        case glsl:\n")
24464
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintClampNV($p, $*2)\";\n")
24465
0
SLANG_RAW("        case spirv:\n")
24466
0
SLANG_RAW("            return spirv_asm {\n")
24467
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24468
0
SLANG_RAW("                OpCapability MinLod;\n")
24469
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24470
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24471
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel Bias|MinLod $bias $lodClamp;\n")
24472
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24473
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24474
0
SLANG_RAW("            };\n")
24475
0
SLANG_RAW("        }\n")
24476
0
SLANG_RAW("    }\n")
24477
0
SLANG_RAW("\n")
24478
0
SLANG_RAW("    [__NoSideEffect]\n")
24479
0
SLANG_RAW("    __glsl_version(450)\n")
24480
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24481
0
SLANG_RAW("    [__requiresNVAPI]\n")
24482
0
SLANG_RAW("    [require(glsl_spirv, texturefootprint)]\n")
24483
0
SLANG_RAW("    bool __queryFootprintLodGLSL(\n")
24484
0
SLANG_RAW("            SamplerState            sampler,\n")
24485
0
SLANG_RAW("            Coords                  coords,\n")
24486
0
SLANG_RAW("            float                   lod,\n")
24487
0
SLANG_RAW("            int                     granularity,\n")
24488
0
SLANG_RAW("            bool                    useCoarseLevel,\n")
24489
0
SLANG_RAW("            out __FootprintData         footprint)\n")
24490
0
SLANG_RAW("    {\n")
24491
0
SLANG_RAW("        __target_switch\n")
24492
0
SLANG_RAW("        {\n")
24493
0
SLANG_RAW("        case glsl:\n")
24494
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintLodNV($p, $*2)\";\n")
24495
0
SLANG_RAW("        case spirv:\n")
24496
0
SLANG_RAW("            return spirv_asm {\n")
24497
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24498
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24499
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24500
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel Lod $lod;\n")
24501
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24502
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24503
0
SLANG_RAW("            };\n")
24504
0
SLANG_RAW("        }\n")
24505
0
SLANG_RAW("    }\n")
24506
0
SLANG_RAW("\n")
24507
0
SLANG_RAW("\n")
24508
24509
    // Texture sampling with gradient is only available for 2D textures.
24510
0
SLANG_RAW("#line 22316 \"hlsl.meta.slang\"")
24511
0
SLANG_RAW("\n")
24512
0
SLANG_RAW("    [__NoSideEffect]\n")
24513
0
SLANG_RAW("    __glsl_version(450)\n")
24514
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24515
0
SLANG_RAW("    [__requiresNVAPI]\n")
24516
0
SLANG_RAW("    [require(glsl_spirv, texturefootprint)]\n")
24517
0
SLANG_RAW("    bool __queryFootprintGradGLSL(\n")
24518
0
SLANG_RAW("            SamplerState    sampler,\n")
24519
0
SLANG_RAW("            Coords          coords,\n")
24520
0
SLANG_RAW("            Coords          dx,\n")
24521
0
SLANG_RAW("            Coords          dy,\n")
24522
0
SLANG_RAW("            int             granularity,\n")
24523
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24524
0
SLANG_RAW("            out __FootprintData footprint)\n")
24525
0
SLANG_RAW("    {\n")
24526
0
SLANG_RAW("        __target_switch\n")
24527
0
SLANG_RAW("        {\n")
24528
0
SLANG_RAW("        case glsl:\n")
24529
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintGradNV($p, $*2)\";\n")
24530
0
SLANG_RAW("        case spirv:\n")
24531
0
SLANG_RAW("            return spirv_asm {\n")
24532
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24533
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24534
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24535
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel Grad $dx $dy;\n")
24536
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24537
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24538
0
SLANG_RAW("            };\n")
24539
0
SLANG_RAW("        }\n")
24540
0
SLANG_RAW("    }\n")
24541
0
SLANG_RAW("\n")
24542
0
SLANG_RAW("    [__NoSideEffect]\n")
24543
0
SLANG_RAW("    __glsl_version(450)\n")
24544
0
SLANG_RAW("    __glsl_extension(GL_NV_shader_texture_footprint)\n")
24545
0
SLANG_RAW("    __glsl_extension(GL_ARB_sparse_texture_clamp)\n")
24546
0
SLANG_RAW("    [require(glsl_spirv, texturefootprintclamp)]\n")
24547
0
SLANG_RAW("    bool __queryFootprintGradClampGLSL(\n")
24548
0
SLANG_RAW("            SamplerState    sampler,\n")
24549
0
SLANG_RAW("            Coords          coords,\n")
24550
0
SLANG_RAW("            Coords          dx,\n")
24551
0
SLANG_RAW("            Coords          dy,\n")
24552
0
SLANG_RAW("            float           lodClamp,\n")
24553
0
SLANG_RAW("            int             granularity,\n")
24554
0
SLANG_RAW("            bool            useCoarseLevel,\n")
24555
0
SLANG_RAW("            out __FootprintData footprint)\n")
24556
0
SLANG_RAW("    {\n")
24557
0
SLANG_RAW("        __target_switch\n")
24558
0
SLANG_RAW("        {\n")
24559
0
SLANG_RAW("        case glsl:\n")
24560
0
SLANG_RAW("            __intrinsic_asm \"textureFootprintGradClampNV($p, $*2)\";\n")
24561
0
SLANG_RAW("        case spirv:\n")
24562
0
SLANG_RAW("            return spirv_asm {\n")
24563
0
SLANG_RAW("                OpCapability ImageFootprintNV;\n")
24564
0
SLANG_RAW("                OpCapability MinLod;\n")
24565
0
SLANG_RAW("                OpExtension \"SPV_NV_shader_image_footprint\";\n")
24566
0
SLANG_RAW("                %sampledImage : __sampledImageType(this) = OpSampledImage $this $sampler;\n")
24567
0
SLANG_RAW("                %resultVal:$$__FootprintData = OpImageSampleFootprintNV %sampledImage $coords $granularity $useCoarseLevel Grad|MinLod $dx $dy $lodClamp;\n")
24568
0
SLANG_RAW("                OpStore &footprint %resultVal;\n")
24569
0
SLANG_RAW("                result:$$bool = OpCompositeExtract %resultVal 0;\n")
24570
0
SLANG_RAW("            };\n")
24571
0
SLANG_RAW("        }\n")
24572
0
SLANG_RAW("    }\n")
24573
24574
    // End texture2D specific functions.
24575
0
SLANG_RAW("#line 22380 \"hlsl.meta.slang\"")
24576
0
SLANG_RAW("\n")
24577
0
SLANG_RAW("\n")
24578
0
SLANG_RAW("\n")
24579
24580
// The NVAPI texture query operations encode the choice
24581
// between coarse and fine levels as part of the function
24582
// name, and so we are forced to match this convention
24583
// if we want to provide a more portable API.
24584
//
24585
// TODO: We could conceivably define the functions to use
24586
// a parameter for the coarse/fine choice, which is required
24587
// to be `constexpr` for the HLSL/NVAPI target.
24588
//
24589
0
static const struct LevelChoice
24590
0
{
24591
0
char const* name;
24592
0
char const* isCoarseVal;
24593
0
} kLevelChoices[] =
24594
0
{
24595
0
    { "Coarse", "true" },
24596
0
    { "Fine", "false" },
24597
0
};
24598
0
for(auto levelChoice : kLevelChoices)
24599
0
{
24600
0
    auto CoarseOrFine = levelChoice.name;
24601
0
    auto isCoarseVal = levelChoice.isCoarseVal;
24602
24603
// We now go ahead and define the intrinsics provided by NVAPI,
24604
// which have a very different signature from the GLSL ones.
24605
//
24606
// Note: the NVAPI functions also support an optional texel
24607
// offset parameter. For now we are not including overloads
24608
// with that parameter, since they have no equivalent in
24609
// the GLSL extension.
24610
//
24611
0
SLANG_RAW("#line 22415 \"hlsl.meta.slang\"")
24612
0
SLANG_RAW("\n")
24613
0
SLANG_RAW("\n")
24614
0
SLANG_RAW("    [__NoSideEffect]\n")
24615
0
SLANG_RAW("    [__requiresNVAPI]\n")
24616
0
SLANG_RAW("    [require(hlsl, texturefootprint)]\n")
24617
0
SLANG_RAW("    static __FootprintData __queryFootprint")
24618
0
SLANG_SPLICE(CoarseOrFine
24619
0
)
24620
0
SLANG_RAW("NVAPI(\n")
24621
0
SLANG_RAW("        int                     nd,\n")
24622
0
SLANG_RAW("        uint                    textureSpace,\n")
24623
0
SLANG_RAW("        uint                    textureIndex,\n")
24624
0
SLANG_RAW("        uint                    samplerSpace,\n")
24625
0
SLANG_RAW("        uint                    samplerIndex,\n")
24626
0
SLANG_RAW("        float3                  coords,\n")
24627
0
SLANG_RAW("        FootprintGranularity    granularity,\n")
24628
0
SLANG_RAW("        out uint                isSingleLod)\n")
24629
0
SLANG_RAW("    {\n")
24630
0
SLANG_RAW("        __target_switch\n")
24631
0
SLANG_RAW("        {\n")
24632
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvFootprint")
24633
0
SLANG_SPLICE(CoarseOrFine
24634
0
)
24635
0
SLANG_RAW("($1, $2, $3, $4, NV_EXTN_TEXTURE_$!0D, $*5)\";\n")
24636
0
SLANG_RAW("        }\n")
24637
0
SLANG_RAW("    }\n")
24638
0
SLANG_RAW("\n")
24639
0
SLANG_RAW("    [__NoSideEffect]\n")
24640
0
SLANG_RAW("    [__requiresNVAPI]\n")
24641
0
SLANG_RAW("    [require(hlsl, texturefootprint)]\n")
24642
0
SLANG_RAW("    static __FootprintData __queryFootprint")
24643
0
SLANG_SPLICE(CoarseOrFine
24644
0
)
24645
0
SLANG_RAW("BiasNVAPI(\n")
24646
0
SLANG_RAW("        int                     nd,\n")
24647
0
SLANG_RAW("        uint                    textureSpace,\n")
24648
0
SLANG_RAW("        uint                    textureIndex,\n")
24649
0
SLANG_RAW("        uint                    samplerSpace,\n")
24650
0
SLANG_RAW("        uint                    samplerIndex,\n")
24651
0
SLANG_RAW("        float3                  coords,\n")
24652
0
SLANG_RAW("        FootprintGranularity    granularity,\n")
24653
0
SLANG_RAW("        float                   lodBias,\n")
24654
0
SLANG_RAW("        out uint                isSingleLod)\n")
24655
0
SLANG_RAW("    {\n")
24656
0
SLANG_RAW("        __target_switch\n")
24657
0
SLANG_RAW("        {\n")
24658
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvFootprint")
24659
0
SLANG_SPLICE(CoarseOrFine
24660
0
)
24661
0
SLANG_RAW("Bias($1, $2, $3, $4, NV_EXTN_TEXTURE_$!0D, $*5)\";\n")
24662
0
SLANG_RAW("        }\n")
24663
0
SLANG_RAW("    }\n")
24664
0
SLANG_RAW("\n")
24665
0
SLANG_RAW("    [__NoSideEffect]\n")
24666
0
SLANG_RAW("    [__requiresNVAPI]\n")
24667
0
SLANG_RAW("    [require(hlsl, texturefootprint)]\n")
24668
0
SLANG_RAW("    static __FootprintData __queryFootprint")
24669
0
SLANG_SPLICE(CoarseOrFine
24670
0
)
24671
0
SLANG_RAW("LevelNVAPI(\n")
24672
0
SLANG_RAW("        int                     nd,\n")
24673
0
SLANG_RAW("        uint                    textureSpace,\n")
24674
0
SLANG_RAW("        uint                    textureIndex,\n")
24675
0
SLANG_RAW("        uint                    samplerSpace,\n")
24676
0
SLANG_RAW("        uint                    samplerIndex,\n")
24677
0
SLANG_RAW("        float3                  coords,\n")
24678
0
SLANG_RAW("        FootprintGranularity    granularity,\n")
24679
0
SLANG_RAW("        float                   lod,\n")
24680
0
SLANG_RAW("        out uint                isSingleLod)\n")
24681
0
SLANG_RAW("    {\n")
24682
0
SLANG_RAW("        __target_switch\n")
24683
0
SLANG_RAW("        {\n")
24684
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvFootprint")
24685
0
SLANG_SPLICE(CoarseOrFine
24686
0
)
24687
0
SLANG_RAW("Level($1, $2, $3, $4, NV_EXTN_TEXTURE_$!0D, $*5)\";\n")
24688
0
SLANG_RAW("        }\n")
24689
0
SLANG_RAW("    }\n")
24690
0
SLANG_RAW("\n")
24691
0
SLANG_RAW("    [__NoSideEffect]\n")
24692
0
SLANG_RAW("    [__requiresNVAPI]\n")
24693
0
SLANG_RAW("    [require(hlsl, texturefootprint)]\n")
24694
0
SLANG_RAW("    static __FootprintData __queryFootprint")
24695
0
SLANG_SPLICE(CoarseOrFine
24696
0
)
24697
0
SLANG_RAW("GradNVAPI(\n")
24698
0
SLANG_RAW("        int                     nd,\n")
24699
0
SLANG_RAW("        uint                    textureSpace,\n")
24700
0
SLANG_RAW("        uint                    textureIndex,\n")
24701
0
SLANG_RAW("        uint                    samplerSpace,\n")
24702
0
SLANG_RAW("        uint                    samplerIndex,\n")
24703
0
SLANG_RAW("        float3                  coords,\n")
24704
0
SLANG_RAW("        FootprintGranularity    granularity,\n")
24705
0
SLANG_RAW("        float3                  dx,\n")
24706
0
SLANG_RAW("        float3                  dy,\n")
24707
0
SLANG_RAW("        out uint                isSingleLod)\n")
24708
0
SLANG_RAW("    {\n")
24709
0
SLANG_RAW("        __target_switch\n")
24710
0
SLANG_RAW("        {\n")
24711
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"NvFootprint")
24712
0
SLANG_SPLICE(CoarseOrFine
24713
0
)
24714
0
SLANG_RAW("Grad($1, $2, $3, $4, NV_EXTN_TEXTURE_$!0D, $*5)\";\n")
24715
0
SLANG_RAW("        }\n")
24716
0
SLANG_RAW("    }\n")
24717
0
SLANG_RAW("\n")
24718
24719
// We now define the portable operations that will be officially
24720
// supported by the standard module. For each operation, we
24721
// need to provide both a version that maps to the GLSL extension,
24722
// and a version that uses the NVAPI functions.
24723
//
24724
// Some function variations are only available with one extension
24725
// or the other, so we try our best to only define them where
24726
// each is available.
24727
//
24728
// Note that these functions cannot be marked as [ForceInline] for now
24729
// because the texture resource may get removed after DCE, since the only
24730
// use of those resources are done through __GetRegisterIndex/Space, which is
24731
// replaced early with their binding slot in the compilation process.
24732
// Not inlining these function is a quick way to make sure the texture always
24733
// has live uses.
24734
//
24735
0
SLANG_RAW("#line 22514 \"hlsl.meta.slang\"")
24736
0
SLANG_RAW("\n")
24737
0
SLANG_RAW("\n")
24738
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24739
0
SLANG_RAW("    ///\n")
24740
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24741
0
SLANG_RAW("    /// by a comparable call to:\n")
24742
0
SLANG_RAW("    ///\n")
24743
0
SLANG_RAW("    ///     t.Sample(sampler, coords);\n")
24744
0
SLANG_RAW("    ///\n")
24745
0
SLANG_RAW("    [__NoSideEffect]\n")
24746
0
SLANG_RAW("    Footprint queryFootprint")
24747
0
SLANG_SPLICE(CoarseOrFine
24748
0
)
24749
0
SLANG_RAW("(\n")
24750
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24751
0
SLANG_RAW("            SamplerState            sampler,\n")
24752
0
SLANG_RAW("            Coords                  coords)\n")
24753
0
SLANG_RAW("    {\n")
24754
0
SLANG_RAW("        __target_switch\n")
24755
0
SLANG_RAW("        {\n")
24756
0
SLANG_RAW("        case glsl:\n")
24757
0
SLANG_RAW("        case spirv:\n")
24758
0
SLANG_RAW("            Footprint footprint;\n")
24759
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintGLSL(sampler, coords, granularity, ")
24760
0
SLANG_SPLICE(isCoarseVal
24761
0
)
24762
0
SLANG_RAW(", footprint);\n")
24763
0
SLANG_RAW("            return footprint;\n")
24764
0
SLANG_RAW("\n")
24765
0
SLANG_RAW("        case hlsl:\n")
24766
0
SLANG_RAW("            uint isSingleLod = 0;\n")
24767
0
SLANG_RAW("            __queryFootprint")
24768
0
SLANG_SPLICE(CoarseOrFine
24769
0
)
24770
0
SLANG_RAW("NVAPI(\n")
24771
0
SLANG_RAW("                Shape.dimensions,\n")
24772
0
SLANG_RAW("                __getRegisterSpace(this), __getRegisterIndex(this),\n")
24773
0
SLANG_RAW("                __getRegisterSpace(sampler), __getRegisterIndex(sampler),\n")
24774
0
SLANG_RAW("                __vectorReshape<3>(coords), granularity, /* out */isSingleLod);\n")
24775
0
SLANG_RAW("            Footprint footprint = {false};\n")
24776
0
SLANG_RAW("            footprint._isSingleLevel = (isSingleLod != 0);\n")
24777
0
SLANG_RAW("            return footprint;\n")
24778
0
SLANG_RAW("        }\n")
24779
0
SLANG_RAW("    }\n")
24780
0
SLANG_RAW("\n")
24781
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24782
0
SLANG_RAW("    ///\n")
24783
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24784
0
SLANG_RAW("    /// by a comparable call to:\n")
24785
0
SLANG_RAW("    ///\n")
24786
0
SLANG_RAW("    ///     t.SampleBias(sampler, coords, lodBias);\n")
24787
0
SLANG_RAW("    ///\n")
24788
0
SLANG_RAW("    [__NoSideEffect]\n")
24789
0
SLANG_RAW("    Footprint queryFootprint")
24790
0
SLANG_SPLICE(CoarseOrFine
24791
0
)
24792
0
SLANG_RAW("Bias(\n")
24793
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24794
0
SLANG_RAW("            SamplerState            sampler,\n")
24795
0
SLANG_RAW("            Coords                  coords,\n")
24796
0
SLANG_RAW("            float                   lodBias)\n")
24797
0
SLANG_RAW("    {\n")
24798
0
SLANG_RAW("        __target_switch\n")
24799
0
SLANG_RAW("        {\n")
24800
0
SLANG_RAW("        case glsl:\n")
24801
0
SLANG_RAW("        case spirv:\n")
24802
0
SLANG_RAW("            Footprint footprint;\n")
24803
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintGLSL(sampler, coords, granularity, ")
24804
0
SLANG_SPLICE(isCoarseVal
24805
0
)
24806
0
SLANG_RAW(", footprint, lodBias);\n")
24807
0
SLANG_RAW("            return footprint;\n")
24808
0
SLANG_RAW("        case hlsl:\n")
24809
0
SLANG_RAW("            uint isSingleLod = 0;\n")
24810
0
SLANG_RAW("            __queryFootprint")
24811
0
SLANG_SPLICE(CoarseOrFine
24812
0
)
24813
0
SLANG_RAW("BiasNVAPI(\n")
24814
0
SLANG_RAW("                Shape.dimensions,\n")
24815
0
SLANG_RAW("                __getRegisterSpace(this), __getRegisterIndex(this),\n")
24816
0
SLANG_RAW("                __getRegisterSpace(sampler), __getRegisterIndex(sampler),\n")
24817
0
SLANG_RAW("                __vectorReshape<3>(coords), granularity, lodBias, /* out */isSingleLod);\n")
24818
0
SLANG_RAW("            Footprint footprint = {false};\n")
24819
0
SLANG_RAW("            footprint._isSingleLevel = (isSingleLod != 0);\n")
24820
0
SLANG_RAW("            return footprint;\n")
24821
0
SLANG_RAW("        }\n")
24822
0
SLANG_RAW("    }\n")
24823
0
SLANG_RAW("\n")
24824
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24825
0
SLANG_RAW("    ///\n")
24826
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24827
0
SLANG_RAW("    /// by a comparable call to:\n")
24828
0
SLANG_RAW("    ///\n")
24829
0
SLANG_RAW("    ///     t.SampleClamp(sampler, coords, lodClamp);\n")
24830
0
SLANG_RAW("    ///\n")
24831
0
SLANG_RAW("    [__NoSideEffect]\n")
24832
0
SLANG_RAW("    Footprint queryFootprint")
24833
0
SLANG_SPLICE(CoarseOrFine
24834
0
)
24835
0
SLANG_RAW("Clamp(\n")
24836
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24837
0
SLANG_RAW("            SamplerState            sampler,\n")
24838
0
SLANG_RAW("            Coords                  coords,\n")
24839
0
SLANG_RAW("            float                   lodClamp)\n")
24840
0
SLANG_RAW("    {\n")
24841
0
SLANG_RAW("        __target_switch\n")
24842
0
SLANG_RAW("        {\n")
24843
0
SLANG_RAW("        case glsl:\n")
24844
0
SLANG_RAW("        case spirv:\n")
24845
0
SLANG_RAW("            Footprint footprint;\n")
24846
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintClampGLSL(sampler, coords, lodClamp, granularity, ")
24847
0
SLANG_SPLICE(isCoarseVal
24848
0
)
24849
0
SLANG_RAW(", footprint);\n")
24850
0
SLANG_RAW("            return footprint;\n")
24851
0
SLANG_RAW("        }\n")
24852
0
SLANG_RAW("    }\n")
24853
0
SLANG_RAW("\n")
24854
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24855
0
SLANG_RAW("    ///\n")
24856
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24857
0
SLANG_RAW("    /// by a comparable call to:\n")
24858
0
SLANG_RAW("    ///\n")
24859
0
SLANG_RAW("    ///     t.SampleBiasClamp(sampler, coords, lodBias, lodClamp);\n")
24860
0
SLANG_RAW("    ///\n")
24861
0
SLANG_RAW("    [__NoSideEffect]\n")
24862
0
SLANG_RAW("    Footprint queryFootprint")
24863
0
SLANG_SPLICE(CoarseOrFine
24864
0
)
24865
0
SLANG_RAW("BiasClamp(\n")
24866
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24867
0
SLANG_RAW("            SamplerState            sampler,\n")
24868
0
SLANG_RAW("            Coords                  coords,\n")
24869
0
SLANG_RAW("            float                   lodBias,\n")
24870
0
SLANG_RAW("            float                   lodClamp)\n")
24871
0
SLANG_RAW("    {\n")
24872
0
SLANG_RAW("        __target_switch\n")
24873
0
SLANG_RAW("        {\n")
24874
0
SLANG_RAW("        case glsl:\n")
24875
0
SLANG_RAW("        case spirv:\n")
24876
0
SLANG_RAW("            Footprint footprint;\n")
24877
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintClampGLSL(sampler, coords, lodClamp, granularity, ")
24878
0
SLANG_SPLICE(isCoarseVal
24879
0
)
24880
0
SLANG_RAW(", footprint, lodBias);\n")
24881
0
SLANG_RAW("            return footprint;\n")
24882
0
SLANG_RAW("        }\n")
24883
0
SLANG_RAW("    }\n")
24884
0
SLANG_RAW("\n")
24885
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24886
0
SLANG_RAW("    ///\n")
24887
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24888
0
SLANG_RAW("    /// by a comparable call to:\n")
24889
0
SLANG_RAW("    ///\n")
24890
0
SLANG_RAW("    ///     t.SampleLevel(sampler, coords, lod);\n")
24891
0
SLANG_RAW("    ///\n")
24892
0
SLANG_RAW("    [__NoSideEffect]\n")
24893
0
SLANG_RAW("    Footprint queryFootprint")
24894
0
SLANG_SPLICE(CoarseOrFine
24895
0
)
24896
0
SLANG_RAW("Level(\n")
24897
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24898
0
SLANG_RAW("            SamplerState            sampler,\n")
24899
0
SLANG_RAW("            Coords                  coords,\n")
24900
0
SLANG_RAW("            float                   lod)\n")
24901
0
SLANG_RAW("    {\n")
24902
0
SLANG_RAW("        __target_switch\n")
24903
0
SLANG_RAW("        {\n")
24904
0
SLANG_RAW("        case glsl:\n")
24905
0
SLANG_RAW("        case spirv:\n")
24906
0
SLANG_RAW("            Footprint footprint;\n")
24907
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintLodGLSL(sampler, coords, lod, granularity, ")
24908
0
SLANG_SPLICE(isCoarseVal
24909
0
)
24910
0
SLANG_RAW(", footprint);\n")
24911
0
SLANG_RAW("            return footprint;\n")
24912
0
SLANG_RAW("        case hlsl:\n")
24913
0
SLANG_RAW("            uint isSingleLod = 0;\n")
24914
0
SLANG_RAW("            __queryFootprint")
24915
0
SLANG_SPLICE(CoarseOrFine
24916
0
)
24917
0
SLANG_RAW("LevelNVAPI(\n")
24918
0
SLANG_RAW("                Shape.dimensions,\n")
24919
0
SLANG_RAW("                __getRegisterSpace(this), __getRegisterIndex(this),\n")
24920
0
SLANG_RAW("                __getRegisterSpace(sampler), __getRegisterIndex(sampler),\n")
24921
0
SLANG_RAW("                __vectorReshape<3>(coords), granularity, lod, /* out */isSingleLod);\n")
24922
0
SLANG_RAW("            Footprint footprint = {false};\n")
24923
0
SLANG_RAW("            footprint._isSingleLevel = (isSingleLod != 0);\n")
24924
0
SLANG_RAW("            return footprint;\n")
24925
0
SLANG_RAW("        }\n")
24926
0
SLANG_RAW("    }\n")
24927
0
SLANG_RAW("\n")
24928
24929
    // TODO: Texture sampling with gradient is only available for 2D textures.
24930
0
SLANG_RAW("#line 22669 \"hlsl.meta.slang\"")
24931
0
SLANG_RAW("\n")
24932
0
SLANG_RAW("\n")
24933
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24934
0
SLANG_RAW("    ///\n")
24935
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24936
0
SLANG_RAW("    /// by a comparable call to:\n")
24937
0
SLANG_RAW("    ///\n")
24938
0
SLANG_RAW("    ///     t.SampleGrad(sampler, coords, dx, dy);\n")
24939
0
SLANG_RAW("    ///\n")
24940
0
SLANG_RAW("    [__NoSideEffect] [ForceInline]\n")
24941
0
SLANG_RAW("    Footprint queryFootprint")
24942
0
SLANG_SPLICE(CoarseOrFine
24943
0
)
24944
0
SLANG_RAW("Grad(\n")
24945
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24946
0
SLANG_RAW("            SamplerState            sampler,\n")
24947
0
SLANG_RAW("            Coords                  coords,\n")
24948
0
SLANG_RAW("            Coords                  dx,\n")
24949
0
SLANG_RAW("            Coords                  dy)\n")
24950
0
SLANG_RAW("    {\n")
24951
0
SLANG_RAW("        __target_switch\n")
24952
0
SLANG_RAW("        {\n")
24953
0
SLANG_RAW("        case glsl:\n")
24954
0
SLANG_RAW("        case spirv:\n")
24955
0
SLANG_RAW("            Footprint footprint;\n")
24956
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintGradGLSL(sampler, coords, dx, dy, granularity, ")
24957
0
SLANG_SPLICE(isCoarseVal
24958
0
)
24959
0
SLANG_RAW(", footprint);\n")
24960
0
SLANG_RAW("            return footprint;\n")
24961
0
SLANG_RAW("        case hlsl:\n")
24962
0
SLANG_RAW("            uint isSingleLod = 0;\n")
24963
0
SLANG_RAW("            __queryFootprint")
24964
0
SLANG_SPLICE(CoarseOrFine
24965
0
)
24966
0
SLANG_RAW("GradNVAPI(\n")
24967
0
SLANG_RAW("                Shape.dimensions,\n")
24968
0
SLANG_RAW("                __getRegisterSpace(this), __getRegisterIndex(this),\n")
24969
0
SLANG_RAW("                __getRegisterSpace(sampler), __getRegisterIndex(sampler),\n")
24970
0
SLANG_RAW("                __vectorReshape<3>(coords), granularity, __vectorReshape<3>(dx), __vectorReshape<3>(dy), /* out */isSingleLod);\n")
24971
0
SLANG_RAW("            Footprint footprint = {false};\n")
24972
0
SLANG_RAW("            footprint._isSingleLevel = (isSingleLod != 0);\n")
24973
0
SLANG_RAW("            return footprint;\n")
24974
0
SLANG_RAW("        }\n")
24975
0
SLANG_RAW("    }\n")
24976
0
SLANG_RAW("\n")
24977
0
SLANG_RAW("    /// Query the footprint that would be accessed by a texture sampling operation.\n")
24978
0
SLANG_RAW("    ///\n")
24979
0
SLANG_RAW("    /// This operation queries the footprint that would be accessed\n")
24980
0
SLANG_RAW("    /// by a comparable call to:\n")
24981
0
SLANG_RAW("    ///\n")
24982
0
SLANG_RAW("    ///     t.SampleGradClamp(sampler, coords, dx, dy, lodClamp);\n")
24983
0
SLANG_RAW("    ///\n")
24984
0
SLANG_RAW("    [__NoSideEffect][ForceInline]\n")
24985
0
SLANG_RAW("    Footprint queryFootprint")
24986
0
SLANG_SPLICE(CoarseOrFine
24987
0
)
24988
0
SLANG_RAW("GradClamp(\n")
24989
0
SLANG_RAW("            FootprintGranularity    granularity,\n")
24990
0
SLANG_RAW("            SamplerState            sampler,\n")
24991
0
SLANG_RAW("            Coords                  coords,\n")
24992
0
SLANG_RAW("            Coords                  dx,\n")
24993
0
SLANG_RAW("            Coords                  dy,\n")
24994
0
SLANG_RAW("            float                   lodClamp)\n")
24995
0
SLANG_RAW("    {\n")
24996
0
SLANG_RAW("        __target_switch\n")
24997
0
SLANG_RAW("        {\n")
24998
0
SLANG_RAW("        case glsl:\n")
24999
0
SLANG_RAW("        case spirv:\n")
25000
0
SLANG_RAW("            Footprint footprint;\n")
25001
0
SLANG_RAW("            footprint._isSingleLevel = __queryFootprintGradClampGLSL(sampler, coords, dx, dy, lodClamp, granularity, ")
25002
0
SLANG_SPLICE(isCoarseVal
25003
0
)
25004
0
SLANG_RAW(", footprint);\n")
25005
0
SLANG_RAW("            return footprint;\n")
25006
0
SLANG_RAW("        }\n")
25007
0
SLANG_RAW("    }\n")
25008
0
SLANG_RAW("\n")
25009
25010
    // TODO: end texture2D specific functions.
25011
0
SLANG_RAW("#line 22734 \"hlsl.meta.slang\"")
25012
0
SLANG_RAW("\n")
25013
0
SLANG_RAW("\n")
25014
25015
0
}
25016
0
SLANG_RAW("#line 22738 \"hlsl.meta.slang\"")
25017
0
SLANG_RAW("\n")
25018
0
SLANG_RAW("\n")
25019
0
SLANG_RAW("} // extension\n")
25020
0
SLANG_RAW("\n")
25021
0
SLANG_RAW("//<T, Shape: __ITextureShape, let isArray:int, let isMS:int, let sampleCount:int, let access:int, let isShadow:int, let isCombined:int, let format:int>\n")
25022
0
SLANG_RAW("__generic<Shape:__ITextureShape1D2D3D, let format : int>\n")
25023
0
SLANG_RAW("extension _Texture<float, Shape, 0, 0, 0, ")
25024
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadWrite
25025
0
)
25026
0
SLANG_RAW(", 0, 0, format>\n")
25027
0
SLANG_RAW("{\n")
25028
0
SLANG_RAW("    [__requiresNVAPI]\n")
25029
0
SLANG_RAW("    [ForceInline]\n")
25030
0
SLANG_RAW("    __glsl_extension(GL_EXT_shader_atomic_float)\n")
25031
0
SLANG_RAW("    [require(glsl_hlsl_metal_spirv, atomic_glsl_hlsl_nvapi_cuda_metal_float1)]\n")
25032
0
SLANG_RAW("    void InterlockedAddF32(vector<uint, Shape.dimensions> coord, float value, out float originalValue)\n")
25033
0
SLANG_RAW("    {\n")
25034
0
SLANG_RAW("        __target_switch\n")
25035
0
SLANG_RAW("        {\n")
25036
0
SLANG_RAW("        case hlsl:\n")
25037
0
SLANG_RAW("            __intrinsic_asm \"$3 = NvInterlockedAddFp32($0, $1, $2)\";\n")
25038
0
SLANG_RAW("        case glsl:\n")
25039
0
SLANG_RAW("            __intrinsic_asm \"$3 = imageAtomicAdd($0, $1, $2)\";\n")
25040
0
SLANG_RAW("        case metal:\n")
25041
0
SLANG_RAW("            originalValue = __atomic_add(this[coord], value);\n")
25042
0
SLANG_RAW("            return;\n")
25043
0
SLANG_RAW("        default:\n")
25044
0
SLANG_RAW("            originalValue = __atomic_add(this[coord], value);\n")
25045
0
SLANG_RAW("            return;\n")
25046
0
SLANG_RAW("        }\n")
25047
0
SLANG_RAW("    }\n")
25048
0
SLANG_RAW("\n")
25049
0
SLANG_RAW("    [ForceInline]\n")
25050
0
SLANG_RAW("    float InterlockedAddF32(vector<uint, Shape.dimensions> coord, float value)\n")
25051
0
SLANG_RAW("    {\n")
25052
0
SLANG_RAW("        float originalValue;\n")
25053
0
SLANG_RAW("        InterlockedAddF32(coord, value, originalValue);\n")
25054
0
SLANG_RAW("        return originalValue;\n")
25055
0
SLANG_RAW("    }\n")
25056
0
SLANG_RAW("}\n")
25057
0
SLANG_RAW("\n")
25058
0
SLANG_RAW("// Buffer Pointer\n")
25059
0
SLANG_RAW("\n")
25060
0
SLANG_RAW("//@hidden:\n")
25061
0
SLANG_RAW("\n")
25062
0
SLANG_RAW("namespace vk\n")
25063
0
SLANG_RAW("{\n")
25064
0
SLANG_RAW("    // Partial implementation of the vk::buffer_ref proposal:\n")
25065
0
SLANG_RAW("    // https://github.com/microsoft/hlsl-specs/blob/main/proposals/0010-vk-buffer-ref.md\n")
25066
0
SLANG_RAW("    struct BufferPointer<T, let Alignment : int = 0>\n")
25067
0
SLANG_RAW("    {\n")
25068
0
SLANG_RAW("        T *_ptr;\n")
25069
0
SLANG_RAW("        [ForceInline] __init(T *ptr) { _ptr = ptr; }\n")
25070
0
SLANG_RAW("        [ForceInline] __init(uint64_t val) { _ptr = (T *)val; }\n")
25071
0
SLANG_RAW("        [ForceInline] Ref<T> Get() { return *_ptr; }\n")
25072
0
SLANG_RAW("        [ForceInline] T *getPtr() { return _ptr;}\n")
25073
0
SLANG_RAW("    }\n")
25074
0
SLANG_RAW("    [ForceInline]\n")
25075
0
SLANG_RAW("    BufferPointer<U, alignment> static_pointer_cast<U, let alignment : int = 0, T, let a : int>(BufferPointer<T, a> src)\n")
25076
0
SLANG_RAW("    {\n")
25077
0
SLANG_RAW("        return BufferPointer<U, alignment>((U*)(src.getPtr()));\n")
25078
0
SLANG_RAW("    }\n")
25079
0
SLANG_RAW("    [ForceInline]\n")
25080
0
SLANG_RAW("    BufferPointer<U, alignment> reinterpret_pointer_cast<U, let alignment : int = 0, T, let a : int>(BufferPointer<T, a> src)\n")
25081
0
SLANG_RAW("    {\n")
25082
0
SLANG_RAW("        return BufferPointer<U, alignment>((U *)(src.getPtr()));\n")
25083
0
SLANG_RAW("    }\n")
25084
0
SLANG_RAW("}\n")
25085
0
SLANG_RAW("\n")
25086
0
SLANG_RAW("attribute_syntax[vk_aliased_pointer] : VkAliasedPointerAttribute;\n")
25087
0
SLANG_RAW("attribute_syntax[vk_restrict_pointer] : VkRestrictPointerAttribute;\n")
25088
0
SLANG_RAW("\n")
25089
0
SLANG_RAW("extension uint64_t\n")
25090
0
SLANG_RAW("{\n")
25091
0
SLANG_RAW("    __init<T, let alignment : int>(vk::BufferPointer<T, alignment> ptr)\n")
25092
0
SLANG_RAW("    {\n")
25093
0
SLANG_RAW("        this = (uint64_t)ptr._ptr;\n")
25094
0
SLANG_RAW("    }\n")
25095
0
SLANG_RAW("}\n")
25096
0
SLANG_RAW("\n")
25097
0
SLANG_RAW("struct ConstBufferPointer<T, int alignment = 16>\n")
25098
0
SLANG_RAW("{\n")
25099
0
SLANG_RAW("    T *_ptr;\n")
25100
0
SLANG_RAW("\n")
25101
0
SLANG_RAW("    [ForceInline] T get() { return loadAligned<alignment>(_ptr); }\n")
25102
0
SLANG_RAW("\n")
25103
0
SLANG_RAW("    __subscript(int index) -> T\n")
25104
0
SLANG_RAW("    {\n")
25105
0
SLANG_RAW("        [ForceInline]\n")
25106
0
SLANG_RAW("        get { return _ptr[index]; }\n")
25107
0
SLANG_RAW("    }\n")
25108
0
SLANG_RAW("\n")
25109
0
SLANG_RAW("    [ForceInline] T* getPtr() { return _ptr; }\n")
25110
0
SLANG_RAW("\n")
25111
0
SLANG_RAW("    [ForceInline]\n")
25112
0
SLANG_RAW("    static ConstBufferPointer<T> fromUInt(uint64_t val)\n")
25113
0
SLANG_RAW("    {\n")
25114
0
SLANG_RAW("        return ConstBufferPointer<T>(val);\n")
25115
0
SLANG_RAW("    }\n")
25116
0
SLANG_RAW("\n")
25117
0
SLANG_RAW("    [ForceInline]\n")
25118
0
SLANG_RAW("    uint64_t toUInt()\n")
25119
0
SLANG_RAW("    {\n")
25120
0
SLANG_RAW("        return (uint64_t)_ptr;\n")
25121
0
SLANG_RAW("    }\n")
25122
0
SLANG_RAW("\n")
25123
0
SLANG_RAW("    [ForceInline]\n")
25124
0
SLANG_RAW("    bool isValid()\n")
25125
0
SLANG_RAW("    {\n")
25126
0
SLANG_RAW("        return _ptr != nullptr;\n")
25127
0
SLANG_RAW("    }\n")
25128
0
SLANG_RAW("\n")
25129
0
SLANG_RAW("    __init(T* val)\n")
25130
0
SLANG_RAW("    {\n")
25131
0
SLANG_RAW("        _ptr = val;\n")
25132
0
SLANG_RAW("    }\n")
25133
0
SLANG_RAW("\n")
25134
0
SLANG_RAW("    __init(uint64_t val)\n")
25135
0
SLANG_RAW("    {\n")
25136
0
SLANG_RAW("        _ptr = (T*)val;\n")
25137
0
SLANG_RAW("    }\n")
25138
0
SLANG_RAW("}\n")
25139
0
SLANG_RAW("//\n")
25140
0
SLANG_RAW("// HLSL-like dynamic resources\n")
25141
0
SLANG_RAW("// https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_DynamicResources.html\n")
25142
0
SLANG_RAW("//\n")
25143
0
SLANG_RAW("// For Khronos targets, `__DynamicResource` can be used to declare \"untyped\" global bindings as\n")
25144
0
SLANG_RAW("// usual (e.g. unsized arrays for descriptor indexing), which will then be materialized into\n")
25145
0
SLANG_RAW("// new aliased bindings for each distinct cast type.\n")
25146
0
SLANG_RAW("//\n")
25147
0
SLANG_RAW("\n")
25148
0
SLANG_RAW("//@public:\n")
25149
0
SLANG_RAW("\n")
25150
0
SLANG_RAW("/// Represent the kind of a descriptor type.\n")
25151
0
SLANG_RAW("enum DescriptorKind\n")
25152
0
SLANG_RAW("{\n")
25153
0
SLANG_RAW("    Unknown, /// Unknown descriptor kind.\n")
25154
0
SLANG_RAW("    Texture, /// A texture descriptor.\n")
25155
0
SLANG_RAW("    CombinedTextureSampler, /// A combined texture and sampler state descriptor.\n")
25156
0
SLANG_RAW("    ConstantBuffer, /// A constant buffer descriptor.\n")
25157
0
SLANG_RAW("    StorageBuffer, /// A storage buffer descriptor.\n")
25158
0
SLANG_RAW("    Buffer = StorageBuffer, /// Deprecated. Use `StorageBuffer` instead.\n")
25159
0
SLANG_RAW("    Sampler, /// A sampler state descriptor.\n")
25160
0
SLANG_RAW("    AccelerationStructure, /// A ray tracing acceleration structure descriptor.\n")
25161
0
SLANG_RAW("    UniformTexelBuffer, /// A uniform texel buffer descriptor (read-only).\n")
25162
0
SLANG_RAW("    StorageTexelBuffer /// A storage texel buffer descriptor (read-write).\n")
25163
0
SLANG_RAW("}\n")
25164
0
SLANG_RAW("\n")
25165
0
SLANG_RAW("enum DescriptorAccess\n")
25166
0
SLANG_RAW("{\n")
25167
0
SLANG_RAW("    Unknown = -1,\n")
25168
0
SLANG_RAW("    Read = ")
25169
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadOnly
25170
0
)
25171
0
SLANG_RAW(",\n")
25172
0
SLANG_RAW("    Write = ")
25173
0
SLANG_SPLICE(kCoreModule_ResourceAccessWriteOnly
25174
0
)
25175
0
SLANG_RAW(",\n")
25176
0
SLANG_RAW("    ReadWrite = ")
25177
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadWrite
25178
0
)
25179
0
SLANG_RAW(",\n")
25180
0
SLANG_RAW("    RasterizerOrdered = ")
25181
0
SLANG_SPLICE(kCoreModule_ResourceAccessRasterizerOrdered
25182
0
)
25183
0
SLANG_RAW(",\n")
25184
0
SLANG_RAW("    Feedback = ")
25185
0
SLANG_SPLICE(kCoreModule_ResourceAccessFeedback
25186
0
)
25187
0
SLANG_RAW(",\n")
25188
0
SLANG_RAW("}\n")
25189
0
SLANG_RAW("\n")
25190
0
SLANG_RAW("/// Represents an opaque descriptor type, such as textures, samplers, and buffers etc,\n")
25191
0
SLANG_RAW("/// whose size may be undefined and can't be directly accessed as ordinary data.\n")
25192
0
SLANG_RAW("[sealed]\n")
25193
0
SLANG_RAW("[builtin]\n")
25194
0
SLANG_RAW("interface IOpaqueDescriptor\n")
25195
0
SLANG_RAW("{\n")
25196
0
SLANG_RAW("    /// The kind of the descriptor.\n")
25197
0
SLANG_RAW("    static const DescriptorKind kind;\n")
25198
0
SLANG_RAW("    static const DescriptorAccess descriptorAccess;\n")
25199
0
SLANG_RAW("}\n")
25200
0
SLANG_RAW("\n")
25201
0
SLANG_RAW("__magic_type(DynamicResourceType)\n")
25202
0
SLANG_RAW("__intrinsic_type(")
25203
0
SLANG_SPLICE(kIROp_DynamicResourceType
25204
0
)
25205
0
SLANG_RAW(")\n")
25206
0
SLANG_RAW("struct __DynamicResource<let kind = __DynamicResourceKind.General>\n")
25207
0
SLANG_RAW("{\n")
25208
0
SLANG_RAW("    __intrinsic_op(")
25209
0
SLANG_SPLICE(kIROp_CastDynamicResource
25210
0
)
25211
0
SLANG_RAW(")\n")
25212
0
SLANG_RAW("    T as<T : __IDynamicResourceCastable<kind>>();\n")
25213
0
SLANG_RAW("\n")
25214
0
SLANG_RAW("    __intrinsic_op(")
25215
0
SLANG_SPLICE(kIROp_CastDynamicResource
25216
0
)
25217
0
SLANG_RAW(")\n")
25218
0
SLANG_RAW("    T asOpaqueDescriptor<T : IOpaqueDescriptor>();\n")
25219
0
SLANG_RAW("}\n")
25220
0
SLANG_RAW("interface __IDynamicResourceCastable<let kind = __DynamicResourceKind.General> : IOpaqueDescriptor\n")
25221
0
SLANG_RAW("{\n")
25222
0
SLANG_RAW("}\n")
25223
0
SLANG_RAW("\n")
25224
0
SLANG_RAW("enum __DynamicResourceKind\n")
25225
0
SLANG_RAW("{\n")
25226
0
SLANG_RAW("    General = 0, // CBV_SRV_UAV\n")
25227
0
SLANG_RAW("    Sampler = 1\n")
25228
0
SLANG_RAW("}\n")
25229
0
SLANG_RAW("\n")
25230
0
SLANG_RAW("__generic<T:ITexelElement, Shape : __ITextureShape, let isArray : int, let isMS : int, let sampleCount : int, let access : int, let isShadow : int, let isCombined : int, let format : int>\n")
25231
0
SLANG_RAW("extension _Texture<T, Shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format> : __IDynamicResourceCastable<__DynamicResourceKind.General>\n")
25232
0
SLANG_RAW("{\n")
25233
0
SLANG_RAW("    __intrinsic_op(")
25234
0
SLANG_SPLICE(kIROp_CastDynamicResource
25235
0
)
25236
0
SLANG_RAW(")\n")
25237
0
SLANG_RAW("    __implicit_conversion(")
25238
0
SLANG_SPLICE(kConversionCost_GenericParamUpcast
25239
0
)
25240
0
SLANG_RAW(")\n")
25241
0
SLANG_RAW("    __init(__DynamicResource res);\n")
25242
0
SLANG_RAW("\n")
25243
0
SLANG_RAW("    typealias Handle = DescriptorHandle<This>;\n")
25244
0
SLANG_RAW("\n")
25245
0
SLANG_RAW("    static const DescriptorKind kind = (Shape.flavor == __ShapeBuffer.flavor ?\n")
25246
0
SLANG_RAW("        (access == ")
25247
0
SLANG_SPLICE(kCoreModule_ResourceAccessReadOnly
25248
0
)
25249
0
SLANG_RAW(" ? DescriptorKind.UniformTexelBuffer : DescriptorKind.StorageTexelBuffer) : (isCombined != 0 ? DescriptorKind.CombinedTextureSampler : DescriptorKind.Texture)\n")
25250
0
SLANG_RAW(");\n")
25251
0
SLANG_RAW("    static const DescriptorAccess descriptorAccess = (DescriptorAccess)access;\n")
25252
0
SLANG_RAW("\n")
25253
0
SLANG_RAW("    __implicit_conversion(")
25254
0
SLANG_SPLICE(kConversionCost_ImplicitDereference
25255
0
)
25256
0
SLANG_RAW(")\n")
25257
0
SLANG_RAW("    [ForceInline]\n")
25258
0
SLANG_RAW("    __init(DescriptorHandle<This> bindless)\n")
25259
0
SLANG_RAW("    {\n")
25260
0
SLANG_RAW("        return getDescriptorFromHandle(bindless);\n")
25261
0
SLANG_RAW("    }\n")
25262
0
SLANG_RAW("}\n")
25263
0
SLANG_RAW("\n")
25264
25265
0
struct DynamicResourceTypeInfo
25266
0
{
25267
0
    const char* name;
25268
0
    const char* kind;
25269
0
    const char* dynamicKind;
25270
0
    const char* access;
25271
0
};
25272
25273
0
const DynamicResourceTypeInfo kDynamicResourceCastableTypes[] = {
25274
0
    { "StructuredBuffer<T, L>", "StorageBuffer", "General", "Read" },
25275
0
    { "RWStructuredBuffer<T, L>", "StorageBuffer", "General", "ReadWrite" },
25276
0
    { "AppendStructuredBuffer<T, L>", "StorageBuffer", "General", "ReadWrite" },
25277
0
    { "ConsumeStructuredBuffer<T, L>", "StorageBuffer", "General", "ReadWrite" },
25278
0
    { "RasterizerOrderedStructuredBuffer<T, L>", "StorageBuffer", "General", "ReadWrite" },
25279
0
    { "ByteAddressBuffer", "StorageBuffer", "General", "Read" },
25280
0
    { "RWByteAddressBuffer", "StorageBuffer", "General", "ReadWrite" },
25281
0
    { "RasterizerOrderedByteAddressBuffer", "StorageBuffer", "General", "ReadWrite" },
25282
0
    { "SamplerState", "Sampler", "Sampler", "Unknown" },
25283
0
    { "SamplerComparisonState", "Sampler", "Sampler", "Unknown" },
25284
0
    { "ConstantBuffer<T, L>", "ConstantBuffer", "General", "Read" },
25285
0
    { "TextureBuffer<T>", "UniformTexelBuffer", "General", "Read" },
25286
0
    { "RaytracingAccelerationStructure", "AccelerationStructure", "General", "Read" },
25287
0
};
25288
25289
0
for (auto type : kDynamicResourceCastableTypes) {
25290
0
    auto dynamicKind = type.dynamicKind;
25291
0
    auto kind = type.kind;
25292
0
    auto typeName = type.name;
25293
0
    auto access = type.access;
25294
0
    if (strstr(typeName, "<T, L>"))
25295
0
        sb << "__generic<T, L : IBufferDataLayout>\n";
25296
0
    else if (strstr(typeName, "<T>"))
25297
0
        sb << "__generic<T>\n";
25298
0
SLANG_RAW("#line 22980 \"hlsl.meta.slang\"")
25299
0
SLANG_RAW("\n")
25300
0
SLANG_RAW("\n")
25301
0
SLANG_RAW("extension ")
25302
0
SLANG_SPLICE(typeName
25303
0
)
25304
0
SLANG_RAW(" : __IDynamicResourceCastable<__DynamicResourceKind.")
25305
0
SLANG_SPLICE(dynamicKind
25306
0
)
25307
0
SLANG_RAW(">\n")
25308
0
SLANG_RAW("{\n")
25309
0
SLANG_RAW("    __intrinsic_op(")
25310
0
SLANG_SPLICE(kIROp_CastDynamicResource
25311
0
)
25312
0
SLANG_RAW(")\n")
25313
0
SLANG_RAW("    __implicit_conversion(")
25314
0
SLANG_SPLICE(kConversionCost_GenericParamUpcast
25315
0
)
25316
0
SLANG_RAW(")\n")
25317
0
SLANG_RAW("    __init(__DynamicResource res);\n")
25318
0
SLANG_RAW("\n")
25319
0
SLANG_RAW("    static const DescriptorKind kind = DescriptorKind.")
25320
0
SLANG_SPLICE(kind
25321
0
)
25322
0
SLANG_RAW(";\n")
25323
0
SLANG_RAW("    static const DescriptorAccess descriptorAccess = DescriptorAccess.")
25324
0
SLANG_SPLICE(access
25325
0
)
25326
0
SLANG_RAW(";\n")
25327
0
SLANG_RAW("\n")
25328
0
SLANG_RAW("    typealias Handle = DescriptorHandle<")
25329
0
SLANG_SPLICE(typeName
25330
0
)
25331
0
SLANG_RAW(">;\n")
25332
0
SLANG_RAW("\n")
25333
0
SLANG_RAW("    __implicit_conversion(")
25334
0
SLANG_SPLICE(kConversionCost_ImplicitDereference
25335
0
)
25336
0
SLANG_RAW(")\n")
25337
0
SLANG_RAW("    [ForceInline]\n")
25338
0
SLANG_RAW("    __init(DescriptorHandle<")
25339
0
SLANG_SPLICE(typeName
25340
0
)
25341
0
SLANG_RAW("> bindless)\n")
25342
0
SLANG_RAW("    {\n")
25343
0
SLANG_RAW("        return getDescriptorFromHandle(bindless);\n")
25344
0
SLANG_RAW("    }\n")
25345
0
SLANG_RAW("}\n")
25346
0
SLANG_RAW("\n")
25347
25348
0
}
25349
0
SLANG_RAW("#line 23003 \"hlsl.meta.slang\"")
25350
0
SLANG_RAW("\n")
25351
0
SLANG_RAW("\n")
25352
0
SLANG_RAW("\n")
25353
0
SLANG_RAW("/// Represents a bindless handle to a descriptor. A descriptor handle is always an ordinary data type and can be\n")
25354
0
SLANG_RAW("/// declared in any memory location.\n")
25355
0
SLANG_RAW("/// @remarks Opaque descriptor types such as textures(`Texture2D` etc.), `SamplerState` and buffers (e.g. `StructuredBuffer`)\n")
25356
0
SLANG_RAW("/// can have undefined size and data representation on many targets. On platforms such as Vulkan and D3D12, descriptors are\n")
25357
0
SLANG_RAW("/// communicated to the shader code by calling the host side API to write the descriptor into a descriptor set or table, instead\n")
25358
0
SLANG_RAW("/// of directly writing bytes into an ordinary GPU accessible buffer. As a result, oapque handle types cannot be used in places\n")
25359
0
SLANG_RAW("/// that refer to a ordinary buffer location, such as as element types of a `StructuredBuffer`.\n")
25360
0
SLANG_RAW("/// However, a `DescriptorHandle<T>` stores a handle (or address) to the actual descriptor, and is always an ordinary data type\n")
25361
0
SLANG_RAW("/// that can be manipulated directly in the shader code. This gives the developer the flexibility to embed and pass around descriptor\n")
25362
0
SLANG_RAW("/// parameters throughout the code, to enable cleaner modular designs.\n")
25363
0
SLANG_RAW("/// See [User Guide](https://shader-slang.com/slang/user-guide/convenience-features.html#descriptorhandle-for-bindless-descriptor-access)\n")
25364
0
SLANG_RAW("/// for more information on how to use `DescriptorHandle<T>` in your code.\n")
25365
0
SLANG_RAW("__magic_type(DescriptorHandleType)\n")
25366
0
SLANG_RAW("__intrinsic_type(")
25367
0
SLANG_SPLICE(kIROp_DescriptorHandleType
25368
0
)
25369
0
SLANG_RAW(")\n")
25370
0
SLANG_RAW("struct DescriptorHandle<T:IOpaqueDescriptor> : IComparable\n")
25371
0
SLANG_RAW("{\n")
25372
0
SLANG_RAW("    [require(glsl_spirv)]\n")
25373
0
SLANG_RAW("    [require(hlsl, sm_6_6)]\n")
25374
0
SLANG_RAW("    [require(wgsl)]\n")
25375
0
SLANG_RAW("    __intrinsic_op(")
25376
0
SLANG_SPLICE(kIROp_CastUInt2ToDescriptorHandle
25377
0
)
25378
0
SLANG_RAW(")\n")
25379
0
SLANG_RAW("    __init(uint2 handleValue);\n")
25380
0
SLANG_RAW("\n")
25381
0
SLANG_RAW("    /// Constructor for uint64_t handles\n")
25382
0
SLANG_RAW("    [ForceInline]\n")
25383
0
SLANG_RAW("    [require(spvBindlessTextureNV)]\n")
25384
0
SLANG_RAW("    __intrinsic_op(")
25385
0
SLANG_SPLICE(kIROp_CastUInt64ToDescriptorHandle
25386
0
)
25387
0
SLANG_RAW(")\n")
25388
0
SLANG_RAW("    __init(uint64_t handleValue);\n")
25389
0
SLANG_RAW("\n")
25390
0
SLANG_RAW("    [ForceInline]\n")
25391
0
SLANG_RAW("    bool equals(DescriptorHandle<T> other)\n")
25392
0
SLANG_RAW("    {\n")
25393
0
SLANG_RAW("        __target_switch\n")
25394
0
SLANG_RAW("        {\n")
25395
0
SLANG_RAW("        case spvBindlessTextureNV:\n")
25396
0
SLANG_RAW("            return (uint64_t)this == (uint64_t)other;\n")
25397
0
SLANG_RAW("        default:\n")
25398
0
SLANG_RAW("            return all(__vectorEql((uint2)this, (uint2)other));\n")
25399
0
SLANG_RAW("        }\n")
25400
0
SLANG_RAW("    }\n")
25401
0
SLANG_RAW("\n")
25402
0
SLANG_RAW("    [ForceInline]\n")
25403
0
SLANG_RAW("    bool lessThan(DescriptorHandle<T> other)\n")
25404
0
SLANG_RAW("    {\n")
25405
0
SLANG_RAW("        __target_switch\n")
25406
0
SLANG_RAW("        {\n")
25407
0
SLANG_RAW("        case spvBindlessTextureNV:\n")
25408
0
SLANG_RAW("            return (uint64_t)this < (uint64_t)other;\n")
25409
0
SLANG_RAW("        default:\n")
25410
0
SLANG_RAW("            let vthis = ((uint2)this);\n")
25411
0
SLANG_RAW("            let vother = (uint2)other;\n")
25412
0
SLANG_RAW("            return vthis.x < vother.x || (vthis.x == vother.x && vthis.y < vother.y);\n")
25413
0
SLANG_RAW("        }\n")
25414
0
SLANG_RAW("    }\n")
25415
0
SLANG_RAW("\n")
25416
0
SLANG_RAW("    [ForceInline]\n")
25417
0
SLANG_RAW("    bool lessThanOrEquals(DescriptorHandle<T> other)\n")
25418
0
SLANG_RAW("    {\n")
25419
0
SLANG_RAW("        __target_switch\n")
25420
0
SLANG_RAW("        {\n")
25421
0
SLANG_RAW("        case spvBindlessTextureNV:\n")
25422
0
SLANG_RAW("            return (uint64_t)this <= (uint64_t)other;\n")
25423
0
SLANG_RAW("        default:\n")
25424
0
SLANG_RAW("            let vthis = ((uint2)this);\n")
25425
0
SLANG_RAW("            let vother = (uint2)other;\n")
25426
0
SLANG_RAW("            return vthis.x < vother.x || (vthis.x == vother.x && vthis.y <= vother.y);\n")
25427
0
SLANG_RAW("        }\n")
25428
0
SLANG_RAW("    }\n")
25429
0
SLANG_RAW("}\n")
25430
0
SLANG_RAW("\n")
25431
0
SLANG_RAW("extension uint2\n")
25432
0
SLANG_RAW("{\n")
25433
0
SLANG_RAW("    __intrinsic_op(")
25434
0
SLANG_SPLICE(kIROp_CastDescriptorHandleToUInt2
25435
0
)
25436
0
SLANG_RAW(")\n")
25437
0
SLANG_RAW("    [require(glsl_spirv)]\n")
25438
0
SLANG_RAW("    [require(hlsl, sm_6_6)]\n")
25439
0
SLANG_RAW("    [require(wgsl)]\n")
25440
0
SLANG_RAW("    __init<T:IOpaqueDescriptor>(DescriptorHandle<T> bindless);\n")
25441
0
SLANG_RAW("}\n")
25442
0
SLANG_RAW("\n")
25443
0
SLANG_RAW("extension uint64_t\n")
25444
0
SLANG_RAW("{\n")
25445
0
SLANG_RAW("    __intrinsic_op(")
25446
0
SLANG_SPLICE(kIROp_CastDescriptorHandleToUInt64
25447
0
)
25448
0
SLANG_RAW(")\n")
25449
0
SLANG_RAW("    [require(spvBindlessTextureNV)]\n")
25450
0
SLANG_RAW("    __init<T:IOpaqueDescriptor>(DescriptorHandle<T> bindless);\n")
25451
0
SLANG_RAW("}\n")
25452
0
SLANG_RAW("\n")
25453
0
SLANG_RAW("__generic<T:IOpaqueDescriptor>\n")
25454
0
SLANG_RAW("[ForceInline]\n")
25455
0
SLANG_RAW("__prefix T operator*(DescriptorHandle<T> value)\n")
25456
0
SLANG_RAW("{\n")
25457
0
SLANG_RAW("    return getDescriptorFromHandle(value);\n")
25458
0
SLANG_RAW("}\n")
25459
0
SLANG_RAW("\n")
25460
0
SLANG_RAW("// https://registry.khronos.org/vulkan/specs/latest/man/html/VkDescriptorType.html\n")
25461
0
SLANG_RAW("enum DefaultVkBindlessBindings : uint\n")
25462
0
SLANG_RAW("{\n")
25463
0
SLANG_RAW("    Sampler = 0, /// SAMPLER\n")
25464
0
SLANG_RAW("    CombinedTextureSampler = 1, /// COMBINED_IMAGE_SAMPLER\n")
25465
0
SLANG_RAW("    SampledImage = 2, /// SAMPLED_IMAGE\n")
25466
0
SLANG_RAW("    StorageImage = 3, /// STORAGE_IMAGE\n")
25467
0
SLANG_RAW("    UniformTexelBuffer = 4, /// UNIFORM_TEXEL_BUFFER\n")
25468
0
SLANG_RAW("    StorageTexelBuffer = 5, /// STORAGE_TEXEL_BUFFER\n")
25469
0
SLANG_RAW("    ConstantBuffer_Read = 6, /// UNIFORM_BUFFER\n")
25470
0
SLANG_RAW("    StorageBuffer_Read = 7, /// STORAGE_BUFFER\n")
25471
0
SLANG_RAW("    StorageBuffer_ReadWrite = 7, /// STORAGE_BUFFER\n")
25472
0
SLANG_RAW("    Unknown = 8, /// Other\n")
25473
0
SLANG_RAW("}\n")
25474
0
SLANG_RAW("\n")
25475
0
SLANG_RAW("// https://github.com/KhronosGroup/Vulkan-Docs/blob/main/proposals/VK_EXT_mutable_descriptor_type.adoc\n")
25476
0
SLANG_RAW("enum VkMutableBindlessBindings : uint\n")
25477
0
SLANG_RAW("{\n")
25478
0
SLANG_RAW("    Sampler = 0, /// SAMPLER\n")
25479
0
SLANG_RAW("    CombinedTextureSampler = 1, /// COMBINED_IMAGE_SAMPLER\n")
25480
0
SLANG_RAW("    SampledImage = 2, /// SAMPLED_IMAGE\n")
25481
0
SLANG_RAW("    StorageImage = 2, /// STORAGE_IMAGE\n")
25482
0
SLANG_RAW("    UniformTexelBuffer = 2, /// UNIFORM_TEXEL_BUFFER\n")
25483
0
SLANG_RAW("    StorageTexelBuffer = 2, /// STORAGE_TEXEL_BUFFER\n")
25484
0
SLANG_RAW("    ConstantBuffer_Read = 2, /// UNIFORM_BUFFER\n")
25485
0
SLANG_RAW("    StorageBuffer_Read = 2, /// STORAGE_BUFFER\n")
25486
0
SLANG_RAW("    StorageBuffer_ReadWrite = 2, /// STORAGE_BUFFER,\n")
25487
0
SLANG_RAW("    Unknown = 3, /// Other\n")
25488
0
SLANG_RAW("}\n")
25489
0
SLANG_RAW("\n")
25490
0
SLANG_RAW("__intrinsic_op(")
25491
0
SLANG_SPLICE(kIROp_GetDynamicResourceHeap
25492
0
)
25493
0
SLANG_RAW(")\n")
25494
0
SLANG_RAW("T[] __getDynamicResourceHeap<T:IOpaqueDescriptor>(constexpr uint bindingIndex = 0);\n")
25495
0
SLANG_RAW("\n")
25496
0
SLANG_RAW("\n")
25497
0
SLANG_RAW("// Used by the HLSL backend only, load a sampler state handle from SamplerDescriptorHeap.\n")
25498
0
SLANG_RAW("__intrinsic_op(")
25499
0
SLANG_SPLICE(kIROp_LoadSamplerDescriptorFromHeap
25500
0
)
25501
0
SLANG_RAW(")\n")
25502
0
SLANG_RAW("T __loadSamplerDescriptorFromHeap<T>(uint index);\n")
25503
0
SLANG_RAW("\n")
25504
0
SLANG_RAW("// Used by the HLSL backend only, load a resource handle from ResourceDescriptorHeap.\n")
25505
0
SLANG_RAW("__intrinsic_op(")
25506
0
SLANG_SPLICE(kIROp_LoadResourceDescriptorFromHeap
25507
0
)
25508
0
SLANG_RAW(")\n")
25509
0
SLANG_RAW("T __loadResourceDescriptorFromHeap<T>(uint index);\n")
25510
0
SLANG_RAW("\n")
25511
0
SLANG_RAW("// Used by the HLSL and Metal backends only,\n")
25512
0
SLANG_RAW("// create a combined texture sampler object from a bindless handle.\n")
25513
0
SLANG_RAW("__intrinsic_op(")
25514
0
SLANG_SPLICE(kIROp_MakeCombinedTextureSamplerFromHandle
25515
0
)
25516
0
SLANG_RAW(")\n")
25517
0
SLANG_RAW("T __makeCombinedTextureSamplerFromHandle<T, U>(U handle);\n")
25518
0
SLANG_RAW("\n")
25519
0
SLANG_RAW("__intrinsic_op(")
25520
0
SLANG_SPLICE(kIROp_CastDescriptorHandleToResource
25521
0
)
25522
0
SLANG_RAW(")\n")
25523
0
SLANG_RAW("T __castDescriptorHandleToResource<T:IOpaqueDescriptor>(DescriptorHandle<T> ptr);\n")
25524
0
SLANG_RAW("\n")
25525
0
SLANG_RAW("public enum BindlessDescriptorOptions\n")
25526
0
SLANG_RAW("{\n")
25527
0
SLANG_RAW("    None = 0,      /// Bind assuming regular binding model rules.\n")
25528
0
SLANG_RAW("    VkMutable = 1, /// **Current Default** Bind assuming `VK_EXT_mutable_descriptor_type`\n")
25529
0
SLANG_RAW("}\n")
25530
0
SLANG_RAW("\n")
25531
0
SLANG_RAW("/// The default implementation of `getDescriptorFromHandle`, which converts from a descriptor handle\n")
25532
0
SLANG_RAW("/// to a descriptor object.\n")
25533
0
SLANG_RAW("[ForceInline]\n")
25534
0
SLANG_RAW("T defaultGetDescriptorFromHandle<T:IOpaqueDescriptor>(DescriptorHandle<T> handleValue, constexpr BindlessDescriptorOptions bindlessOptions = BindlessDescriptorOptions.VkMutable)\n")
25535
0
SLANG_RAW("{\n")
25536
0
SLANG_RAW("    __target_switch\n")
25537
0
SLANG_RAW("    {\n")
25538
0
SLANG_RAW("    case hlsl:\n")
25539
0
SLANG_RAW("        if (T.kind == DescriptorKind.Sampler)\n")
25540
0
SLANG_RAW("            return __loadSamplerDescriptorFromHeap<T>(((uint2)handleValue).x);\n")
25541
0
SLANG_RAW("        else if (T.kind == DescriptorKind.CombinedTextureSampler)\n")
25542
0
SLANG_RAW("            return __makeCombinedTextureSamplerFromHandle<T>((uint2)handleValue);\n")
25543
0
SLANG_RAW("        else\n")
25544
0
SLANG_RAW("            return __loadResourceDescriptorFromHeap<T>(((uint2)handleValue).x);\n")
25545
0
SLANG_RAW("    case spvBindlessTextureNV:\n")
25546
0
SLANG_RAW("        return __castDescriptorHandleToResource<T>(handleValue);\n")
25547
0
SLANG_RAW("    case spirv:\n")
25548
0
SLANG_RAW("    case glsl:\n")
25549
0
SLANG_RAW("\n")
25550
0
SLANG_RAW("        switch(bindlessOptions)\n")
25551
0
SLANG_RAW("        {\n")
25552
25553
0
{
25554
0
    static const struct
25555
0
    {
25556
0
        char const* option;
25557
0
        char const* enumType;
25558
0
    }kBindlessOptions[] =
25559
0
    {
25560
0
        {"None", "DefaultVkBindlessBindings"},
25561
0
        {"VkMutable", "VkMutableBindlessBindings"},
25562
0
    };
25563
25564
0
    for(auto bindlessOption : kBindlessOptions)
25565
0
    {
25566
0
        StringBuilder bindlessOptionIfElsePre;
25567
0
        StringBuilder bindlessOptionIfElsePost;
25568
25569
0
        bindlessOptionIfElsePre << "case BindlessDescriptorOptions." << bindlessOption.option <<":\n{\n";
25570
0
        bindlessOptionIfElsePost << "}\n";
25571
0
SLANG_RAW("#line 23194 \"hlsl.meta.slang\"")
25572
0
SLANG_RAW("\n")
25573
0
SLANG_RAW("    ")
25574
0
SLANG_SPLICE(bindlessOptionIfElsePre.toString()
25575
0
)
25576
0
SLANG_RAW("\n")
25577
0
SLANG_RAW("    switch(T.kind)\n")
25578
0
SLANG_RAW("    {\n")
25579
0
SLANG_RAW("    case DescriptorKind.Sampler:\n")
25580
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25581
0
SLANG_SPLICE(bindlessOption.enumType
25582
0
)
25583
0
SLANG_RAW(".Sampler)[((uint2)handleValue).x];\n")
25584
0
SLANG_RAW("    case DescriptorKind.CombinedTextureSampler:\n")
25585
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25586
0
SLANG_SPLICE(bindlessOption.enumType
25587
0
)
25588
0
SLANG_RAW(".CombinedTextureSampler)[((uint2)handleValue).x];\n")
25589
0
SLANG_RAW("    case DescriptorKind.Texture:\n")
25590
0
SLANG_RAW("    {\n")
25591
0
SLANG_RAW("        if(DescriptorAccess.Read == T.descriptorAccess)\n")
25592
0
SLANG_RAW("            return __getDynamicResourceHeap<T>(")
25593
0
SLANG_SPLICE(bindlessOption.enumType
25594
0
)
25595
0
SLANG_RAW(".SampledImage)[((uint2)handleValue).x];\n")
25596
0
SLANG_RAW("        else\n")
25597
0
SLANG_RAW("            return __getDynamicResourceHeap<T>(")
25598
0
SLANG_SPLICE(bindlessOption.enumType
25599
0
)
25600
0
SLANG_RAW(".StorageImage)[((uint2)handleValue).x];\n")
25601
0
SLANG_RAW("    }\n")
25602
0
SLANG_RAW("    case DescriptorKind.UniformTexelBuffer:\n")
25603
0
SLANG_RAW("    {\n")
25604
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25605
0
SLANG_SPLICE(bindlessOption.enumType
25606
0
)
25607
0
SLANG_RAW(".UniformTexelBuffer)[((uint2)handleValue).x];\n")
25608
0
SLANG_RAW("    }\n")
25609
0
SLANG_RAW("    case DescriptorKind.StorageTexelBuffer:\n")
25610
0
SLANG_RAW("    {\n")
25611
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25612
0
SLANG_SPLICE(bindlessOption.enumType
25613
0
)
25614
0
SLANG_RAW(".StorageTexelBuffer)[((uint2)handleValue).x];\n")
25615
0
SLANG_RAW("    }\n")
25616
0
SLANG_RAW("    case DescriptorKind.ConstantBuffer:\n")
25617
0
SLANG_RAW("    {\n")
25618
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25619
0
SLANG_SPLICE(bindlessOption.enumType
25620
0
)
25621
0
SLANG_RAW(".ConstantBuffer_Read)[((uint2)handleValue).x];\n")
25622
0
SLANG_RAW("    }\n")
25623
0
SLANG_RAW("    case DescriptorKind.StorageBuffer:\n")
25624
0
SLANG_RAW("    {\n")
25625
0
SLANG_RAW("        if(DescriptorAccess.Read == T.descriptorAccess)\n")
25626
0
SLANG_RAW("            return __getDynamicResourceHeap<T>(")
25627
0
SLANG_SPLICE(bindlessOption.enumType
25628
0
)
25629
0
SLANG_RAW(".StorageBuffer_Read)[((uint2)handleValue).x];\n")
25630
0
SLANG_RAW("        else\n")
25631
0
SLANG_RAW("            return __getDynamicResourceHeap<T>(")
25632
0
SLANG_SPLICE(bindlessOption.enumType
25633
0
)
25634
0
SLANG_RAW(".StorageBuffer_ReadWrite)[((uint2)handleValue).x];\n")
25635
0
SLANG_RAW("    }\n")
25636
0
SLANG_RAW("    case DescriptorKind.AccelerationStructure:\n")
25637
0
SLANG_RAW("        return __slang_noop_cast<T>(RaytracingAccelerationStructure(__asuint64((uint2)handleValue)));\n")
25638
0
SLANG_RAW("    default:\n")
25639
0
SLANG_RAW("        return __getDynamicResourceHeap<T>(")
25640
0
SLANG_SPLICE(bindlessOption.enumType
25641
0
)
25642
0
SLANG_RAW(".Unknown)[((uint2)handleValue).x];\n")
25643
0
SLANG_RAW("    }\n")
25644
0
SLANG_RAW("    ")
25645
0
SLANG_SPLICE(bindlessOptionIfElsePost.toString()
25646
0
)
25647
0
SLANG_RAW("\n")
25648
25649
0
    }
25650
0
}
25651
0
SLANG_RAW("#line 23237 \"hlsl.meta.slang\"")
25652
0
SLANG_RAW("\n")
25653
0
SLANG_RAW("    default:\n")
25654
0
SLANG_RAW("    {\n")
25655
0
SLANG_RAW("        static_assert(false, \"Impossible to end up here unless something went very wrong\");\n")
25656
0
SLANG_RAW("        return __getDynamicResourceHeap<T>()[((uint2)handleValue).x];\n")
25657
0
SLANG_RAW("    }\n")
25658
0
SLANG_RAW("    }\n")
25659
0
SLANG_RAW("    case wgsl:\n")
25660
0
SLANG_RAW("        return __getDynamicResourceHeap<T>()[((uint2)handleValue).x];\n")
25661
0
SLANG_RAW("    default:\n")
25662
0
SLANG_RAW("        return __castDescriptorHandleToResource<T>(handleValue);\n")
25663
0
SLANG_RAW("    }\n")
25664
0
SLANG_RAW("}\n")
25665
0
SLANG_RAW("\n")
25666
0
SLANG_RAW("/// Declaration of the `getDescriptorFromHandle` that the user code can provide to customize\n")
25667
0
SLANG_RAW("/// how a descriptor handle is converted into a actual descriptor.\n")
25668
0
SLANG_RAW("[ForceInline]\n")
25669
0
SLANG_RAW("extern T getDescriptorFromHandle<T:IOpaqueDescriptor>(DescriptorHandle<T> handleValue)\n")
25670
0
SLANG_RAW("{\n")
25671
0
SLANG_RAW("    return defaultGetDescriptorFromHandle(handleValue);\n")
25672
0
SLANG_RAW("}\n")
25673
0
SLANG_RAW("\n")
25674
0
SLANG_RAW("__intrinsic_op(")
25675
0
SLANG_SPLICE(kIROp_NonUniformResourceIndex
25676
0
)
25677
0
SLANG_RAW(")\n")
25678
0
SLANG_RAW("DescriptorHandle<T> nonuniform<T:IOpaqueDescriptor>(DescriptorHandle<T> ptr);\n")
25679
0
SLANG_RAW("\n")
25680
0
SLANG_RAW("__glsl_version(450)\n")
25681
0
SLANG_RAW("__glsl_extension(GL_ARB_shader_clock)\n")
25682
0
SLANG_RAW("[require(glsl_spirv, GL_ARB_shader_clock)]\n")
25683
0
SLANG_RAW("uint2 clock2x32ARB()\n")
25684
0
SLANG_RAW("{\n")
25685
0
SLANG_RAW("    __target_switch\n")
25686
0
SLANG_RAW("    {\n")
25687
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clock2x32ARB\";\n")
25688
0
SLANG_RAW("    case spirv:\n")
25689
0
SLANG_RAW("        const uint32_t scopeId_subgroup = 3;\n")
25690
0
SLANG_RAW("        return spirv_asm {\n")
25691
0
SLANG_RAW("        OpCapability ShaderClockKHR;\n")
25692
0
SLANG_RAW("        OpExtension \"SPV_KHR_shader_clock\";\n")
25693
0
SLANG_RAW("        result:$$uint2 = OpReadClockKHR $scopeId_subgroup;\n")
25694
0
SLANG_RAW("        };\n")
25695
0
SLANG_RAW("    }\n")
25696
0
SLANG_RAW("}\n")
25697
0
SLANG_RAW("\n")
25698
0
SLANG_RAW("__glsl_version(450)\n")
25699
0
SLANG_RAW("__glsl_extension(GL_ARB_shader_clock)\n")
25700
0
SLANG_RAW("__glsl_extension(GL_ARB_gpu_shader_int64)\n")
25701
0
SLANG_RAW("[require(glsl_spirv, GL_ARB_shader_clock64)]\n")
25702
0
SLANG_RAW("uint64_t clockARB()\n")
25703
0
SLANG_RAW("{\n")
25704
0
SLANG_RAW("    __target_switch\n")
25705
0
SLANG_RAW("    {\n")
25706
0
SLANG_RAW("    case glsl: __intrinsic_asm \"clockARB\";\n")
25707
0
SLANG_RAW("    case spirv:\n")
25708
0
SLANG_RAW("        const uint32_t scopeId_subgroup = 3;\n")
25709
0
SLANG_RAW("        return spirv_asm {\n")
25710
0
SLANG_RAW("            OpCapability ShaderClockKHR;\n")
25711
0
SLANG_RAW("            OpExtension \"SPV_KHR_shader_clock\";\n")
25712
0
SLANG_RAW("            result:$$uint64_t = OpReadClockKHR $scopeId_subgroup;\n")
25713
0
SLANG_RAW("        };\n")
25714
0
SLANG_RAW("    }\n")
25715
0
SLANG_RAW("}\n")
25716
0
SLANG_RAW("\n")
25717
0
SLANG_RAW("extension<T, L : IBufferDataLayout> StructuredBuffer<T, L> : IArray<T>\n")
25718
0
SLANG_RAW("{\n")
25719
0
SLANG_RAW("    int getCount() { uint count; uint stride; this.GetDimensions(count, stride); return count; }\n")
25720
0
SLANG_RAW("}\n")
25721
0
SLANG_RAW("\n")
25722
0
SLANG_RAW("extension<T, L : IBufferDataLayout> RWStructuredBuffer<T, L> : IRWArray<T>\n")
25723
0
SLANG_RAW("{\n")
25724
0
SLANG_RAW("    int getCount() { uint count; uint stride; this.GetDimensions(count, stride); return count; }\n")
25725
0
SLANG_RAW("}\n")
25726
0
SLANG_RAW("\n")
25727
0
SLANG_RAW("extension<T, L : IBufferDataLayout> RasterizerOrderedStructuredBuffer<T, L> : IRWArray<T>\n")
25728
0
SLANG_RAW("{\n")
25729
0
SLANG_RAW("    int getCount() { uint count; uint stride; this.GetDimensions(count, stride); return count; }\n")
25730
0
SLANG_RAW("}\n")
25731
0
SLANG_RAW("\n")
25732
0
SLANG_RAW("[require(vk_mem_model)]\n")
25733
0
SLANG_RAW("internal void enableVMMDeviceScopeCapabilityIfNeeded(constexpr MemoryScope memoryScope)\n")
25734
0
SLANG_RAW("{\n")
25735
0
SLANG_RAW("    if (memoryScope == MemoryScope::Device)\n")
25736
0
SLANG_RAW("    {\n")
25737
0
SLANG_RAW("        spirv_asm\n")
25738
0
SLANG_RAW("        {\n")
25739
0
SLANG_RAW("            OpCapability VulkanMemoryModelDeviceScopeKHR;\n")
25740
0
SLANG_RAW("        };\n")
25741
0
SLANG_RAW("    }\n")
25742
0
SLANG_RAW("}\n")
25743
0
SLANG_RAW("\n")
25744
0
SLANG_RAW("namespace linalg\n")
25745
0
SLANG_RAW("{\n")
25746
0
SLANG_RAW("\n")
25747
0
SLANG_RAW("//\n")
25748
0
SLANG_RAW("// Cooperative Matrix enums\n")
25749
0
SLANG_RAW("//\n")
25750
0
SLANG_RAW("\n")
25751
0
SLANG_RAW("enum CoopMatMatrixUse\n")
25752
0
SLANG_RAW("{\n")
25753
0
SLANG_RAW("    MatrixA = 0,\n")
25754
0
SLANG_RAW("    MatrixB = 1,\n")
25755
0
SLANG_RAW("    MatrixAccumulator = 2,\n")
25756
0
SLANG_RAW("};\n")
25757
0
SLANG_RAW("\n")
25758
0
SLANG_RAW("enum CoopMatMatrixLayout\n")
25759
0
SLANG_RAW("{\n")
25760
0
SLANG_RAW("    RowMajor = 0,\n")
25761
0
SLANG_RAW("    ColumnMajor = 1,\n")
25762
0
SLANG_RAW("};\n")
25763
0
SLANG_RAW("\n")
25764
0
SLANG_RAW("enum CoopMatClampMode\n")
25765
0
SLANG_RAW("{\n")
25766
0
SLANG_RAW("    Undefined,\n")
25767
0
SLANG_RAW("    Constant,\n")
25768
0
SLANG_RAW("    ClampToEdge,\n")
25769
0
SLANG_RAW("    Repeat,\n")
25770
0
SLANG_RAW("    RepeatMirrored\n")
25771
0
SLANG_RAW("};\n")
25772
0
SLANG_RAW("\n")
25773
0
SLANG_RAW("\n")
25774
25775
// SPIRV described that the max value for `Dim` is 5.
25776
//
25777
// https://github.khronos.org/SPIRV-Registry/extensions/NV/SPV_NV_tensor_addressing.html#OpTypeTensorLayoutNV
25778
// OpTypeTensorLayoutNV:
25779
// Dim is the number of dimensions in the tensor layout, and must be a constant
25780
// instruction with scalar 32-bit integer type. The value must be greater than
25781
// zero and less than or equal to 5.
25782
//
25783
// https://github.khronos.org/SPIRV-Registry/extensions/NV/SPV_NV_tensor_addressing.html#OpTypeTensorViewNV
25784
// OpTypeTensorViewNV:
25785
// Dim is the number of dimensions in the tensor view, and must be a constant
25786
// instruction with scalar 32-bit integer type. The value must be greater than
25787
// zero and less than or equal to 5.
25788
//
25789
0
const int kMaxCoopMatTensorDimension = 5;
25790
0
SLANG_RAW("#line 23372 \"hlsl.meta.slang\"")
25791
0
SLANG_RAW("\n")
25792
0
SLANG_RAW("\n")
25793
0
SLANG_RAW("//\n")
25794
0
SLANG_RAW("// TensorLayout\n")
25795
0
SLANG_RAW("//\n")
25796
0
SLANG_RAW("\n")
25797
0
SLANG_RAW("__intrinsic_type(")
25798
0
SLANG_SPLICE(kIROp_TensorAddressingTensorLayoutType
25799
0
)
25800
0
SLANG_RAW(")\n")
25801
0
SLANG_RAW("[require(tensor_addressing)]\n")
25802
0
SLANG_RAW("__generic<\n")
25803
0
SLANG_RAW("    let Dim : uint32_t,\n")
25804
0
SLANG_RAW("    let ClampMode : CoopMatClampMode = CoopMatClampMode.Undefined\n")
25805
0
SLANG_RAW(">\n")
25806
0
SLANG_RAW("struct TensorLayout\n")
25807
0
SLANG_RAW("{\n")
25808
0
SLANG_RAW("    __intrinsic_op(")
25809
0
SLANG_SPLICE(kIROp_MakeTensorAddressingTensorLayout
25810
0
)
25811
0
SLANG_RAW(")\n")
25812
0
SLANG_RAW("    __init();\n")
25813
0
SLANG_RAW("};\n")
25814
0
SLANG_RAW("\n")
25815
0
SLANG_RAW("\n")
25816
25817
0
    for (int iDim = 1; iDim < kMaxCoopMatTensorDimension; ++iDim)
25818
0
    {
25819
0
        StringBuilder dimParams;
25820
0
        StringBuilder dimAsms;
25821
0
        StringBuilder strideParams;
25822
0
        StringBuilder strideAsms;
25823
0
        StringBuilder sliceParams;
25824
0
        StringBuilder sliceAsms;
25825
0
        StringBuilder blockSizeParams;
25826
0
        StringBuilder blockSizeAsms;
25827
0
        for (int j = 1; j < iDim; ++j)
25828
0
        {
25829
0
            dimParams << ", uint32_t dim" << j;
25830
0
            dimAsms << " $dim" << j;
25831
0
            strideParams << ", uint32_t stride" << j;
25832
0
            strideAsms << " $stride" << j;
25833
0
            sliceParams << ", uint32_t offset" << j << ", uint32_t span" << j;
25834
0
            sliceAsms << " $offset" << j << " $span" << j;
25835
0
            blockSizeParams << ", uint32_t blockSize" << j;
25836
0
            blockSizeAsms << " $blockSize" << j;
25837
0
        }
25838
0
SLANG_RAW("#line 23413 \"hlsl.meta.slang\"")
25839
0
SLANG_RAW("\n")
25840
0
SLANG_RAW("\n")
25841
0
SLANG_RAW("\n")
25842
0
SLANG_RAW("extension<\n")
25843
0
SLANG_RAW("    let ClampMode : CoopMatClampMode\n")
25844
0
SLANG_RAW("> TensorLayout<")
25845
0
SLANG_SPLICE(iDim
25846
0
)
25847
0
SLANG_RAW(", ClampMode>\n")
25848
0
SLANG_RAW("{\n")
25849
0
SLANG_RAW("    [require(tensor_addressing)]\n")
25850
0
SLANG_RAW("    This Dimension(uint32_t dim0 ")
25851
0
SLANG_SPLICE(dimParams
25852
0
)
25853
0
SLANG_RAW(")\n")
25854
0
SLANG_RAW("    {\n")
25855
0
SLANG_RAW("        __target_switch\n")
25856
0
SLANG_RAW("        {\n")
25857
0
SLANG_RAW("        case spirv:\n")
25858
0
SLANG_RAW("            return spirv_asm\n")
25859
0
SLANG_RAW("            {\n")
25860
0
SLANG_RAW("                result:$$This = OpTensorLayoutSetDimensionNV $this $dim0 ")
25861
0
SLANG_SPLICE(dimAsms
25862
0
)
25863
0
SLANG_RAW("\n")
25864
0
SLANG_RAW("            };\n")
25865
0
SLANG_RAW("        }\n")
25866
0
SLANG_RAW("    }\n")
25867
0
SLANG_RAW("\n")
25868
0
SLANG_RAW("    [require(tensor_addressing)]\n")
25869
0
SLANG_RAW("    This Stride(uint32_t stride0 ")
25870
0
SLANG_SPLICE(strideParams
25871
0
)
25872
0
SLANG_RAW(")\n")
25873
0
SLANG_RAW("    {\n")
25874
0
SLANG_RAW("        __target_switch\n")
25875
0
SLANG_RAW("        {\n")
25876
0
SLANG_RAW("        case spirv:\n")
25877
0
SLANG_RAW("            return spirv_asm\n")
25878
0
SLANG_RAW("            {\n")
25879
0
SLANG_RAW("                result:$$This = OpTensorLayoutSetStrideNV $this $stride0 ")
25880
0
SLANG_SPLICE(strideAsms
25881
0
)
25882
0
SLANG_RAW(";\n")
25883
0
SLANG_RAW("            };\n")
25884
0
SLANG_RAW("        }\n")
25885
0
SLANG_RAW("    }\n")
25886
0
SLANG_RAW("\n")
25887
0
SLANG_RAW("    [require(tensor_addressing)]\n")
25888
0
SLANG_RAW("    This Slice(uint32_t offset0, uint32_t span0 ")
25889
0
SLANG_SPLICE(sliceParams
25890
0
)
25891
0
SLANG_RAW(")\n")
25892
0
SLANG_RAW("    {\n")
25893
0
SLANG_RAW("        __target_switch\n")
25894
0
SLANG_RAW("        {\n")
25895
0
SLANG_RAW("        case spirv:\n")
25896
0
SLANG_RAW("            return spirv_asm\n")
25897
0
SLANG_RAW("            {\n")
25898
0
SLANG_RAW("                result:$$This = OpTensorLayoutSliceNV $this $offset0 $span0 ")
25899
0
SLANG_SPLICE(sliceAsms
25900
0
)
25901
0
SLANG_RAW(";\n")
25902
0
SLANG_RAW("            };\n")
25903
0
SLANG_RAW("        }\n")
25904
0
SLANG_RAW("    }\n")
25905
0
SLANG_RAW("\n")
25906
0
SLANG_RAW("    [require(tensor_addressing)]\n")
25907
0
SLANG_RAW("    This ClampValue(CoopMatClampMode clampMode)\n")
25908
0
SLANG_RAW("    {\n")
25909
0
SLANG_RAW("        __target_switch\n")
25910
0
SLANG_RAW("        {\n")
25911
0
SLANG_RAW("        case spirv:\n")
25912
0
SLANG_RAW("            return spirv_asm\n")
25913
0
SLANG_RAW("            {\n")
25914
0
SLANG_RAW("                result:$$This = OpTensorLayoutSetClampValueNV $this $clampMode;\n")
25915
0
SLANG_RAW("            };\n")
25916
0
SLANG_RAW("        }\n")
25917
0
SLANG_RAW("    }\n")
25918
0
SLANG_RAW("\n")
25919
0
SLANG_RAW("    [require(tensor_addressing)]\n")
25920
0
SLANG_RAW("    This BlockSize(uint32_t blockSize0 ")
25921
0
SLANG_SPLICE(blockSizeParams
25922
0
)
25923
0
SLANG_RAW(")\n")
25924
0
SLANG_RAW("    {\n")
25925
0
SLANG_RAW("        __target_switch\n")
25926
0
SLANG_RAW("        {\n")
25927
0
SLANG_RAW("        case spirv:\n")
25928
0
SLANG_RAW("            return spirv_asm\n")
25929
0
SLANG_RAW("            {\n")
25930
0
SLANG_RAW("                result:$$This = OpTensorLayoutSetBlockSizeNV $this $blockSize0 ")
25931
0
SLANG_SPLICE(blockSizeAsms
25932
0
)
25933
0
SLANG_RAW(";\n")
25934
0
SLANG_RAW("            };\n")
25935
0
SLANG_RAW("        }\n")
25936
0
SLANG_RAW("    }\n")
25937
0
SLANG_RAW("};\n")
25938
0
SLANG_RAW("\n")
25939
25940
0
    } // iDim
25941
0
SLANG_RAW("#line 23488 \"hlsl.meta.slang\"")
25942
0
SLANG_RAW("\n")
25943
0
SLANG_RAW("\n")
25944
0
SLANG_RAW("//\n")
25945
0
SLANG_RAW("// TensorView\n")
25946
0
SLANG_RAW("//\n")
25947
0
SLANG_RAW("\n")
25948
25949
0
    StringBuilder tensorViewStruct;
25950
0
    for (int j = 0; j < kMaxCoopMatTensorDimension; ++j)
25951
0
    {
25952
        // Assigning the max value as a default value,
25953
        // because the max value is an invalid value and it allows us to check if the value
25954
        // is explicitly set by the user or not.
25955
0
        tensorViewStruct << ", let p" << j << " : uint32_t = 0xff";
25956
0
    }
25957
0
SLANG_RAW("#line 23503 \"hlsl.meta.slang\"")
25958
0
SLANG_RAW("\n")
25959
0
SLANG_RAW("\n")
25960
0
SLANG_RAW("__intrinsic_type(")
25961
0
SLANG_SPLICE(kIROp_TensorAddressingTensorViewType
25962
0
)
25963
0
SLANG_RAW(")\n")
25964
0
SLANG_RAW("__generic<\n")
25965
0
SLANG_RAW("    let Dim : uint32_t,\n")
25966
0
SLANG_RAW("    let HasDimensions : bool\n")
25967
0
SLANG_RAW("    ")
25968
0
SLANG_SPLICE(tensorViewStruct
25969
0
)
25970
0
SLANG_RAW("\n")
25971
0
SLANG_RAW(">\n")
25972
0
SLANG_RAW("struct TensorView\n")
25973
0
SLANG_RAW("{\n")
25974
0
SLANG_RAW("    __intrinsic_op(")
25975
0
SLANG_SPLICE(kIROp_MakeTensorAddressingTensorView
25976
0
)
25977
0
SLANG_RAW(")\n")
25978
0
SLANG_RAW("    __init();\n")
25979
0
SLANG_RAW("};\n")
25980
0
SLANG_RAW("\n")
25981
25982
0
    for (int iDim = 1; iDim < kMaxCoopMatTensorDimension; ++iDim)
25983
0
    {
25984
0
        StringBuilder tensorViewTypes;
25985
0
        StringBuilder tensorViewExtensions;
25986
0
        StringBuilder dimParams;
25987
0
        StringBuilder dimAsms;
25988
0
        StringBuilder strideParams;
25989
0
        StringBuilder strideAsms;
25990
0
        for (int j = 1; j < iDim; ++j)
25991
0
        {
25992
0
            tensorViewTypes << ", let Dim" << j << " : uint32_t";
25993
0
            tensorViewExtensions << ", Dim" << j;
25994
0
            dimParams << ", uint32_t dim" << j;
25995
0
            dimAsms << " $dim" << j;
25996
0
            strideParams << ", uint32_t stride" << j;
25997
0
            strideAsms << " $stride" << j;
25998
0
        }
25999
0
        for (int j = iDim; j < kMaxCoopMatTensorDimension; ++j)
26000
0
        {
26001
0
            tensorViewExtensions << ", 0xff";
26002
0
        }
26003
0
SLANG_RAW("#line 23539 \"hlsl.meta.slang\"")
26004
0
SLANG_RAW("\n")
26005
0
SLANG_RAW("\n")
26006
0
SLANG_RAW("[require(tensor_addressing)]\n")
26007
0
SLANG_RAW("extension<\n")
26008
0
SLANG_RAW("    let HasDimensions : bool,\n")
26009
0
SLANG_RAW("    let Dim0 : uint32_t\n")
26010
0
SLANG_RAW("    ")
26011
0
SLANG_SPLICE(tensorViewTypes
26012
0
)
26013
0
SLANG_RAW("\n")
26014
0
SLANG_RAW("> TensorView<")
26015
0
SLANG_SPLICE(iDim
26016
0
)
26017
0
SLANG_RAW(", HasDimensions, Dim0 ")
26018
0
SLANG_SPLICE(tensorViewExtensions
26019
0
)
26020
0
SLANG_RAW(">\n")
26021
0
SLANG_RAW("{\n")
26022
0
SLANG_RAW("    [require(tensor_addressing)]\n")
26023
0
SLANG_RAW("    This Dimension(uint32_t dim0 ")
26024
0
SLANG_SPLICE(dimParams
26025
0
)
26026
0
SLANG_RAW(")\n")
26027
0
SLANG_RAW("    {\n")
26028
0
SLANG_RAW("        __target_switch\n")
26029
0
SLANG_RAW("        {\n")
26030
0
SLANG_RAW("        case spirv:\n")
26031
0
SLANG_RAW("            return spirv_asm\n")
26032
0
SLANG_RAW("            {\n")
26033
0
SLANG_RAW("                result:$$This = OpTensorViewSetDimensionNV $this $dim0 ")
26034
0
SLANG_SPLICE(dimAsms
26035
0
)
26036
0
SLANG_RAW(";\n")
26037
0
SLANG_RAW("            };\n")
26038
0
SLANG_RAW("        }\n")
26039
0
SLANG_RAW("    }\n")
26040
0
SLANG_RAW("\n")
26041
0
SLANG_RAW("    [require(tensor_addressing)]\n")
26042
0
SLANG_RAW("    This Stride(uint32_t stride0 ")
26043
0
SLANG_SPLICE(strideParams
26044
0
)
26045
0
SLANG_RAW(")\n")
26046
0
SLANG_RAW("    {\n")
26047
0
SLANG_RAW("        __target_switch\n")
26048
0
SLANG_RAW("        {\n")
26049
0
SLANG_RAW("        case spirv:\n")
26050
0
SLANG_RAW("            return spirv_asm\n")
26051
0
SLANG_RAW("            {\n")
26052
0
SLANG_RAW("                result:$$This = OpTensorViewSetStrideNV $this $stride0 ")
26053
0
SLANG_SPLICE(strideAsms
26054
0
)
26055
0
SLANG_RAW(";\n")
26056
0
SLANG_RAW("            };\n")
26057
0
SLANG_RAW("        }\n")
26058
0
SLANG_RAW("    }\n")
26059
0
SLANG_RAW("\n")
26060
0
SLANG_RAW("    [require(tensor_addressing)]\n")
26061
0
SLANG_RAW("    This Clip(uint clipRowOffset, uint clipRowSpan, uint clipColOffset, uint clipColSpan)\n")
26062
0
SLANG_RAW("    {\n")
26063
0
SLANG_RAW("        __target_switch\n")
26064
0
SLANG_RAW("        {\n")
26065
0
SLANG_RAW("        case spirv:\n")
26066
0
SLANG_RAW("            return spirv_asm\n")
26067
0
SLANG_RAW("            {\n")
26068
0
SLANG_RAW("                result:$$This = OpTensorViewSetClipNV $this $clipRowOffset $clipRowSpan $clipColOffset $clipColSpan;\n")
26069
0
SLANG_RAW("            };\n")
26070
0
SLANG_RAW("        }\n")
26071
0
SLANG_RAW("    }\n")
26072
0
SLANG_RAW("};\n")
26073
0
SLANG_RAW("\n")
26074
26075
0
    } // iDim
26076
0
SLANG_RAW("#line 23590 \"hlsl.meta.slang\"")
26077
0
SLANG_RAW("\n")
26078
0
SLANG_RAW("\n")
26079
0
SLANG_RAW("\n")
26080
0
SLANG_RAW("//\n")
26081
0
SLANG_RAW("// Cooperative Matrix type\n")
26082
0
SLANG_RAW("//\n")
26083
0
SLANG_RAW("\n")
26084
0
SLANG_RAW("__intrinsic_type(")
26085
0
SLANG_SPLICE(kIROp_CoopMatrixType
26086
0
)
26087
0
SLANG_RAW(")\n")
26088
0
SLANG_RAW("[require(cooperative_matrix)]\n")
26089
0
SLANG_RAW("__generic<\n")
26090
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
26091
0
SLANG_RAW("    let S : MemoryScope,\n")
26092
0
SLANG_RAW("    let M : int,\n")
26093
0
SLANG_RAW("    let N : int,\n")
26094
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
26095
0
SLANG_RAW(">\n")
26096
0
SLANG_RAW("struct CoopMat\n")
26097
0
SLANG_RAW("    : IArray<T>\n")
26098
0
SLANG_RAW("    , IArithmetic\n")
26099
0
SLANG_RAW("{\n")
26100
0
SLANG_RAW("    //\n")
26101
0
SLANG_RAW("    // Initialization\n")
26102
0
SLANG_RAW("    //\n")
26103
0
SLANG_RAW("\n")
26104
0
SLANG_RAW("    [ForceInline]\n")
26105
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26106
0
SLANG_RAW("    __init()\n")
26107
0
SLANG_RAW("    {\n")
26108
0
SLANG_RAW("    }\n")
26109
0
SLANG_RAW("\n")
26110
0
SLANG_RAW("    [ForceInline]\n")
26111
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26112
0
SLANG_RAW("    __init(T t)\n")
26113
0
SLANG_RAW("    {\n")
26114
0
SLANG_RAW("        this.fill(t);\n")
26115
0
SLANG_RAW("    }\n")
26116
0
SLANG_RAW("\n")
26117
0
SLANG_RAW("    [ForceInline]\n")
26118
0
SLANG_RAW("    [require(cooperative_matrix_conversion)]\n")
26119
0
SLANG_RAW("    __init<\n")
26120
0
SLANG_RAW("        U : __BuiltinArithmeticType\n")
26121
0
SLANG_RAW("    >(CoopMat<U, S, M, N, R> other)\n")
26122
0
SLANG_RAW("    {\n")
26123
0
SLANG_RAW("        this.copyFrom(other);\n")
26124
0
SLANG_RAW("    }\n")
26125
0
SLANG_RAW("\n")
26126
0
SLANG_RAW("    [ForceInline]\n")
26127
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26128
0
SLANG_RAW("    __init(This x)\n")
26129
0
SLANG_RAW("    {\n")
26130
0
SLANG_RAW("        this = x;\n")
26131
0
SLANG_RAW("    }\n")
26132
0
SLANG_RAW("\n")
26133
0
SLANG_RAW("    // Required for `IArithmetic`.\n")
26134
0
SLANG_RAW("    [ForceInline]\n")
26135
0
SLANG_RAW("    [OverloadRank(-10)]\n")
26136
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26137
0
SLANG_RAW("    __init(int i)\n")
26138
0
SLANG_RAW("    {\n")
26139
0
SLANG_RAW("        this = CoopMat<T, S, M, N, R>(T(i));\n")
26140
0
SLANG_RAW("    }\n")
26141
0
SLANG_RAW("\n")
26142
0
SLANG_RAW("    //\n")
26143
0
SLANG_RAW("    // Simple setters\n")
26144
0
SLANG_RAW("    //\n")
26145
0
SLANG_RAW("\n")
26146
0
SLANG_RAW("    /// Fills the cooperative matrix with the specified value.\n")
26147
0
SLANG_RAW("    /// @param t The value to fill the matrix with.\n")
26148
0
SLANG_RAW("    [ForceInline]\n")
26149
0
SLANG_RAW("    [mutating]\n")
26150
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26151
0
SLANG_RAW("    void fill(T t)\n")
26152
0
SLANG_RAW("    {\n")
26153
0
SLANG_RAW("        this = spirv_asm\n")
26154
0
SLANG_RAW("        {\n")
26155
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpConstantComposite $t;\n")
26156
0
SLANG_RAW("        };\n")
26157
0
SLANG_RAW("    }\n")
26158
0
SLANG_RAW("\n")
26159
0
SLANG_RAW("    /// Copies the contents from another cooperative matrix into this matrix.\n")
26160
0
SLANG_RAW("    /// @param U The element type of the source cooperative matrix.\n")
26161
0
SLANG_RAW("    /// @param other The source cooperative matrix to copy from.\n")
26162
0
SLANG_RAW("    [ForceInline]\n")
26163
0
SLANG_RAW("    [mutating]\n")
26164
0
SLANG_RAW("    [require(cooperative_matrix_conversion)]\n")
26165
0
SLANG_RAW("    void copyFrom<\n")
26166
0
SLANG_RAW("        U : __BuiltinArithmeticType\n")
26167
0
SLANG_RAW("    >(CoopMat<U, S, M, N, R> other)\n")
26168
0
SLANG_RAW("    {\n")
26169
0
SLANG_RAW("        if (__isFloat<T>() && __isInt<U>())\n")
26170
0
SLANG_RAW("            this = __int_to_float_cast<T>(other);\n")
26171
0
SLANG_RAW("        else if (__isInt<T>() && __isFloat<U>())\n")
26172
0
SLANG_RAW("            this = __float_to_int_cast<T>(other);\n")
26173
0
SLANG_RAW("        else if (__isFloat<T>() && __isFloat<U>())\n")
26174
0
SLANG_RAW("            this = __real_cast<T>(other);\n")
26175
0
SLANG_RAW("        else if (__isInt<T>() && __isInt<U>())\n")
26176
0
SLANG_RAW("            this = __int_cast<T>(other);\n")
26177
0
SLANG_RAW("    }\n")
26178
0
SLANG_RAW("\n")
26179
0
SLANG_RAW("    //\n")
26180
0
SLANG_RAW("    // Subscript\n")
26181
0
SLANG_RAW("    //\n")
26182
0
SLANG_RAW("\n")
26183
0
SLANG_RAW("    __intrinsic_op(")
26184
0
SLANG_SPLICE(kIROp_GetElement
26185
0
)
26186
0
SLANG_RAW(")\n")
26187
0
SLANG_RAW("    [__NoSideEffect]\n")
26188
0
SLANG_RAW("    T __indexRead(int index);\n")
26189
0
SLANG_RAW("\n")
26190
0
SLANG_RAW("    __intrinsic_op(")
26191
0
SLANG_SPLICE(kIROp_GetElementPtr
26192
0
)
26193
0
SLANG_RAW(")\n")
26194
0
SLANG_RAW("    [__ref]\n")
26195
0
SLANG_RAW("    [__NoSideEffect]\n")
26196
0
SLANG_RAW("    Ref<T> __indexRef(int index);\n")
26197
0
SLANG_RAW("\n")
26198
0
SLANG_RAW("    /// Returns the count as an integer value.\n")
26199
0
SLANG_RAW("    [ForceInline]\n")
26200
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26201
0
SLANG_RAW("    [__NoSideEffect]\n")
26202
0
SLANG_RAW("    int getCount()\n")
26203
0
SLANG_RAW("    {\n")
26204
0
SLANG_RAW("        return GetLength();\n")
26205
0
SLANG_RAW("    }\n")
26206
0
SLANG_RAW("\n")
26207
0
SLANG_RAW("    __subscript(int index) -> T\n")
26208
0
SLANG_RAW("    {\n")
26209
0
SLANG_RAW("        [__NoSideEffect]\n")
26210
0
SLANG_RAW("        [nonmutating]\n")
26211
0
SLANG_RAW("        get\n")
26212
0
SLANG_RAW("        {\n")
26213
0
SLANG_RAW("            return __indexRead(index);\n")
26214
0
SLANG_RAW("        }\n")
26215
0
SLANG_RAW("\n")
26216
0
SLANG_RAW("        [mutating]\n")
26217
0
SLANG_RAW("        set\n")
26218
0
SLANG_RAW("        {\n")
26219
0
SLANG_RAW("            __indexRef(index) = newValue;\n")
26220
0
SLANG_RAW("        }\n")
26221
0
SLANG_RAW("    }\n")
26222
0
SLANG_RAW("\n")
26223
0
SLANG_RAW("    //\n")
26224
0
SLANG_RAW("    // CoopMat operations\n")
26225
0
SLANG_RAW("    //\n")
26226
0
SLANG_RAW("\n")
26227
0
SLANG_RAW("    /// Returns the number of elements for the current thread.\n")
26228
0
SLANG_RAW("    /// Depending on the number of threads for the given matrix, each\n")
26229
0
SLANG_RAW("    /// thread will get smaller length.\n")
26230
0
SLANG_RAW("    ///\n")
26231
0
SLANG_RAW("    /// @remarks The return value is unlikely to be same to M * N.\n")
26232
0
SLANG_RAW("    [ForceInline]\n")
26233
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26234
0
SLANG_RAW("    static uint GetLength()\n")
26235
0
SLANG_RAW("    {\n")
26236
0
SLANG_RAW("        return spirv_asm\n")
26237
0
SLANG_RAW("        {\n")
26238
0
SLANG_RAW("            result:$$uint = OpCooperativeMatrixLengthKHR $$CoopMat<T, S, M, N, R>;\n")
26239
0
SLANG_RAW("        };\n")
26240
0
SLANG_RAW("    }\n")
26241
0
SLANG_RAW("\n")
26242
0
SLANG_RAW("    /// Returns the number of rows in the matrix.\n")
26243
0
SLANG_RAW("    [ForceInline]\n")
26244
0
SLANG_RAW("    [__NoSideEffect]\n")
26245
0
SLANG_RAW("    static int GetRowCount()\n")
26246
0
SLANG_RAW("    {\n")
26247
0
SLANG_RAW("        return M;\n")
26248
0
SLANG_RAW("    }\n")
26249
0
SLANG_RAW("\n")
26250
0
SLANG_RAW("    /// Returns the number of columns in the matrix.\n")
26251
0
SLANG_RAW("    [ForceInline]\n")
26252
0
SLANG_RAW("    [__NoSideEffect]\n")
26253
0
SLANG_RAW("    static int GetColumnCount()\n")
26254
0
SLANG_RAW("    {\n")
26255
0
SLANG_RAW("        return N;\n")
26256
0
SLANG_RAW("    }\n")
26257
0
SLANG_RAW("\n")
26258
0
SLANG_RAW("    [require(cooperative_matrix_conversion)]\n")
26259
0
SLANG_RAW("    CoopMat<T, S, N, M, CoopMatMatrixUse.MatrixB> Transpose()\n")
26260
0
SLANG_RAW("    {\n")
26261
0
SLANG_RAW("        return spirv_asm\n")
26262
0
SLANG_RAW("        {\n")
26263
0
SLANG_RAW("            OpCapability CooperativeMatrixConversionsNV;\n")
26264
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26265
0
SLANG_RAW("            result:$$CoopMat<T, S, N, M, CoopMatMatrixUse.MatrixB> = OpCooperativeMatrixTransposeNV $this;\n")
26266
0
SLANG_RAW("        };\n")
26267
0
SLANG_RAW("    }\n")
26268
0
SLANG_RAW("\n")
26269
0
SLANG_RAW("    [require(cooperative_matrix_reduction)]\n")
26270
0
SLANG_RAW("    CoopMat<T, S, M, RN, CoopMatMatrixUse.MatrixAccumulator> ReduceRow<\n")
26271
0
SLANG_RAW("        let RN : int\n")
26272
0
SLANG_RAW("    >(functype(T, T) -> T combineOp)\n")
26273
0
SLANG_RAW("    {\n")
26274
0
SLANG_RAW("        return spirv_asm\n")
26275
0
SLANG_RAW("        {\n")
26276
0
SLANG_RAW("            OpCapability CooperativeMatrixReductionsNV;\n")
26277
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26278
0
SLANG_RAW("            result:$$CoopMat<T, S, M, RN, CoopMatMatrixUse.MatrixAccumulator> = OpCooperativeMatrixReduceNV $this Row $combineOp;\n")
26279
0
SLANG_RAW("        };\n")
26280
0
SLANG_RAW("    }\n")
26281
0
SLANG_RAW("\n")
26282
0
SLANG_RAW("    [require(cooperative_matrix_reduction)]\n")
26283
0
SLANG_RAW("    CoopMat<T, S, RM, N, CoopMatMatrixUse.MatrixAccumulator> ReduceColumn<\n")
26284
0
SLANG_RAW("        let RM : int\n")
26285
0
SLANG_RAW("    >(functype(T, T) -> T combineOp)\n")
26286
0
SLANG_RAW("    {\n")
26287
0
SLANG_RAW("        return spirv_asm\n")
26288
0
SLANG_RAW("        {\n")
26289
0
SLANG_RAW("            OpCapability CooperativeMatrixReductionsNV;\n")
26290
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26291
0
SLANG_RAW("            result:$$CoopMat<T, S, RM, N, CoopMatMatrixUse.MatrixAccumulator> = OpCooperativeMatrixReduceNV $this Column $combineOp;\n")
26292
0
SLANG_RAW("        };\n")
26293
0
SLANG_RAW("    }\n")
26294
0
SLANG_RAW("\n")
26295
0
SLANG_RAW("    [require(cooperative_matrix_reduction)]\n")
26296
0
SLANG_RAW("    CoopMat<T, S, RM, RN, CoopMatMatrixUse.MatrixAccumulator> ReduceRowAndColumn<\n")
26297
0
SLANG_RAW("        let RM : int,\n")
26298
0
SLANG_RAW("        let RN : int\n")
26299
0
SLANG_RAW("    >(functype(T, T) -> T combineOp)\n")
26300
0
SLANG_RAW("    {\n")
26301
0
SLANG_RAW("        return spirv_asm\n")
26302
0
SLANG_RAW("        {\n")
26303
0
SLANG_RAW("            OpCapability CooperativeMatrixReductionsNV;\n")
26304
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26305
0
SLANG_RAW("            result:$$CoopMat<T, S, RM, RN, CoopMatMatrixUse.MatrixAccumulator> = OpCooperativeMatrixReduceNV $this Row|Column $combineOp;\n")
26306
0
SLANG_RAW("        };\n")
26307
0
SLANG_RAW("    }\n")
26308
0
SLANG_RAW("\n")
26309
0
SLANG_RAW("    [require(cooperative_matrix_reduction)]\n")
26310
0
SLANG_RAW("    CoopMat<T, S, M / 2, N / 2, CoopMatMatrixUse.MatrixAccumulator> Reduce2x2(functype(T, T)->T combineOp)\n")
26311
0
SLANG_RAW("    {\n")
26312
0
SLANG_RAW("        return spirv_asm\n")
26313
0
SLANG_RAW("        {\n")
26314
0
SLANG_RAW("            OpCapability CooperativeMatrixReductionsNV;\n")
26315
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26316
0
SLANG_RAW("            result:$$CoopMat<T, S, M / 2, N / 2, CoopMatMatrixUse.MatrixAccumulator> = OpCooperativeMatrixReduceNV $this 0x4 $combineOp;\n")
26317
0
SLANG_RAW("        };\n")
26318
0
SLANG_RAW("    }\n")
26319
0
SLANG_RAW("\n")
26320
0
SLANG_RAW("    [require(cooperative_matrix_map_element)]\n")
26321
0
SLANG_RAW("    This MapElement(functype(uint32_t, uint32_t, T)->T mapOp)\n")
26322
0
SLANG_RAW("    {\n")
26323
0
SLANG_RAW("        return spirv_asm\n")
26324
0
SLANG_RAW("        {\n")
26325
0
SLANG_RAW("            OpCapability CooperativeMatrixPerElementOperationsNV;\n")
26326
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26327
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixPerElementOpNV $this $mapOp;\n")
26328
0
SLANG_RAW("        };\n")
26329
0
SLANG_RAW("    }\n")
26330
0
SLANG_RAW("\n")
26331
0
SLANG_RAW("    __intrinsic_op(")
26332
0
SLANG_SPLICE(kIROp_CoopMatMapElementIFunc
26333
0
)
26334
0
SLANG_RAW(")\n")
26335
0
SLANG_RAW("    internal static This __MapElement<\n")
26336
0
SLANG_RAW("        TOperator,\n")
26337
0
SLANG_RAW("        TFunc : IFunc<T, uint32_t, uint32_t, T>\n")
26338
0
SLANG_RAW("    >(\n")
26339
0
SLANG_RAW("        This coopMat,\n")
26340
0
SLANG_RAW("        TOperator mapOp,\n")
26341
0
SLANG_RAW("        TFunc mapObj\n")
26342
0
SLANG_RAW("    );\n")
26343
0
SLANG_RAW("\n")
26344
0
SLANG_RAW("    This MapElement<\n")
26345
0
SLANG_RAW("        TFunc : IFunc<T, uint32_t, uint32_t, T>\n")
26346
0
SLANG_RAW("    >(TFunc mapOp)\n")
26347
0
SLANG_RAW("    {\n")
26348
0
SLANG_RAW("        return __MapElement(this, mapOp.operator(), mapOp);\n")
26349
0
SLANG_RAW("    }\n")
26350
0
SLANG_RAW("\n")
26351
0
SLANG_RAW("    //\n")
26352
0
SLANG_RAW("    // Store\n")
26353
0
SLANG_RAW("    //\n")
26354
0
SLANG_RAW("\n")
26355
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26356
0
SLANG_RAW("    void Store<\n")
26357
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26358
0
SLANG_RAW("    >(RWByteAddressBuffer buffer, uint element, uint stride)\n")
26359
0
SLANG_RAW("    {\n")
26360
0
SLANG_RAW("        __store<matrixLayout>(__getEquivalentStructuredBuffer<T>(buffer), element, stride);\n")
26361
0
SLANG_RAW("    }\n")
26362
0
SLANG_RAW("\n")
26363
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26364
0
SLANG_RAW("    void Store<\n")
26365
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26366
0
SLANG_RAW("    >(RWStructuredBuffer<T> buffer, uint element, uint stride)\n")
26367
0
SLANG_RAW("    {\n")
26368
0
SLANG_RAW("        __store<matrixLayout>(buffer, element, stride);\n")
26369
0
SLANG_RAW("    }\n")
26370
0
SLANG_RAW("\n")
26371
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26372
0
SLANG_RAW("    internal void __store<\n")
26373
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26374
0
SLANG_RAW("    >(RWStructuredBuffer<T> buffer, uint element, uint stride)\n")
26375
0
SLANG_RAW("    {\n")
26376
0
SLANG_RAW("        let zero = 0;\n")
26377
0
SLANG_RAW("        let alignment = 16U;\n")
26378
0
SLANG_RAW("        spirv_asm\n")
26379
0
SLANG_RAW("        {\n")
26380
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
26381
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
26382
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned !alignment;\n")
26383
0
SLANG_RAW("        };\n")
26384
0
SLANG_RAW("    }\n")
26385
0
SLANG_RAW("\n")
26386
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26387
0
SLANG_RAW("    void Store<\n")
26388
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26389
0
SLANG_RAW("    >(T* buffer, uint element, uint stride)\n")
26390
0
SLANG_RAW("    {\n")
26391
0
SLANG_RAW("        let alignment = 16U;\n")
26392
0
SLANG_RAW("        return spirv_asm\n")
26393
0
SLANG_RAW("        {\n")
26394
0
SLANG_RAW("            %pointer:$$T* = OpPtrAccessChain $buffer $element;\n")
26395
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned !alignment;\n")
26396
0
SLANG_RAW("        };\n")
26397
0
SLANG_RAW("    }\n")
26398
0
SLANG_RAW("\n")
26399
0
SLANG_RAW("    // TODO: make this function an intrinsic and support all types via the single intrinsic\n")
26400
0
SLANG_RAW("    [require(cooperative_matrix, vk_mem_model)]\n")
26401
0
SLANG_RAW("    void StoreCoherent<\n")
26402
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26403
0
SLANG_RAW("    >(T* buffer, uint element, uint stride, constexpr MemoryScope memoryScope)\n")
26404
0
SLANG_RAW("    {\n")
26405
0
SLANG_RAW("        enableVMMDeviceScopeCapabilityIfNeeded(memoryScope);\n")
26406
0
SLANG_RAW("        let alignment = 16U;\n")
26407
0
SLANG_RAW("        const int32_t scope = (int32_t)memoryScope;\n")
26408
0
SLANG_RAW("        return spirv_asm\n")
26409
0
SLANG_RAW("        {\n")
26410
0
SLANG_RAW("            %pointer:$$T* = OpPtrAccessChain $buffer $element;\n")
26411
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned|MakePointerAvailable|NonPrivatePointer !alignment $scope;\n")
26412
0
SLANG_RAW("        };\n")
26413
0
SLANG_RAW("    }\n")
26414
0
SLANG_RAW("\n")
26415
0
SLANG_RAW("    [ForceInline]\n")
26416
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26417
0
SLANG_RAW("    void Store<\n")
26418
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26419
0
SLANG_RAW("        let V : int\n")
26420
0
SLANG_RAW("    >(__ref groupshared T[V] data, uint element, uint stride)\n")
26421
0
SLANG_RAW("    {\n")
26422
0
SLANG_RAW("        let alignment = 16U;\n")
26423
0
SLANG_RAW("        spirv_asm\n")
26424
0
SLANG_RAW("        {\n")
26425
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$T;\n")
26426
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26427
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned !alignment;\n")
26428
0
SLANG_RAW("        };\n")
26429
0
SLANG_RAW("    }\n")
26430
0
SLANG_RAW("\n")
26431
0
SLANG_RAW("    [ForceInline]\n")
26432
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26433
0
SLANG_RAW("    void Store<\n")
26434
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26435
0
SLANG_RAW("        U,\n")
26436
0
SLANG_RAW("        let V : int\n")
26437
0
SLANG_RAW("    >(__ref groupshared U[V] data, uint element, uint stride)\n")
26438
0
SLANG_RAW("    {\n")
26439
0
SLANG_RAW("        let alignment = 16U;\n")
26440
0
SLANG_RAW("        spirv_asm\n")
26441
0
SLANG_RAW("        {\n")
26442
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$U;\n")
26443
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26444
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned !alignment;\n")
26445
0
SLANG_RAW("        };\n")
26446
0
SLANG_RAW("    }\n")
26447
0
SLANG_RAW("\n")
26448
0
SLANG_RAW("    [ForceInline]\n")
26449
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26450
0
SLANG_RAW("    void Store<\n")
26451
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26452
0
SLANG_RAW("        U,\n")
26453
0
SLANG_RAW("        let V : int,\n")
26454
0
SLANG_RAW("        let L : int\n")
26455
0
SLANG_RAW("    >(__ref groupshared vector<U, L>[V] data, uint element, uint stride)\n")
26456
0
SLANG_RAW("    {\n")
26457
0
SLANG_RAW("        let alignment = 16U;\n")
26458
0
SLANG_RAW("        spirv_asm\n")
26459
0
SLANG_RAW("        {\n")
26460
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$vector<U, L>;\n")
26461
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26462
0
SLANG_RAW("            OpCooperativeMatrixStoreKHR %pointer $this $matrixLayout $stride Aligned !alignment;\n")
26463
0
SLANG_RAW("        };\n")
26464
0
SLANG_RAW("    }\n")
26465
0
SLANG_RAW("\n")
26466
0
SLANG_RAW("\n")
26467
0
SLANG_RAW("    //\n")
26468
0
SLANG_RAW("    // Load\n")
26469
0
SLANG_RAW("    //\n")
26470
0
SLANG_RAW("\n")
26471
26472
0
    for (const char* RW : { "", "RW" })
26473
0
    {
26474
0
SLANG_RAW("#line 23975 \"hlsl.meta.slang\"")
26475
0
SLANG_RAW("\n")
26476
0
SLANG_RAW("\n")
26477
0
SLANG_RAW("    [__NoSideEffect]\n")
26478
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26479
0
SLANG_RAW("    static This Load<\n")
26480
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26481
0
SLANG_RAW("    >(\n")
26482
0
SLANG_RAW("        ")
26483
0
SLANG_SPLICE(RW
26484
0
)
26485
0
SLANG_RAW("ByteAddressBuffer buffer,\n")
26486
0
SLANG_RAW("        uint element,\n")
26487
0
SLANG_RAW("        uint stride)\n")
26488
0
SLANG_RAW("    {\n")
26489
0
SLANG_RAW("        return Load<matrixLayout>(__getEquivalentStructuredBuffer<T>(buffer), element, stride);\n")
26490
0
SLANG_RAW("    }\n")
26491
0
SLANG_RAW("\n")
26492
0
SLANG_RAW("    [__NoSideEffect]\n")
26493
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26494
0
SLANG_RAW("    static This Load<\n")
26495
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26496
0
SLANG_RAW("    >(\n")
26497
0
SLANG_RAW("        ")
26498
0
SLANG_SPLICE(RW
26499
0
)
26500
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26501
0
SLANG_RAW("        uint element,\n")
26502
0
SLANG_RAW("        uint stride)\n")
26503
0
SLANG_RAW("    {\n")
26504
0
SLANG_RAW("        let zero = 0;\n")
26505
0
SLANG_RAW("        let alignment = 16U;\n")
26506
0
SLANG_RAW("        return spirv_asm\n")
26507
0
SLANG_RAW("        {\n")
26508
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
26509
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
26510
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned !alignment;\n")
26511
0
SLANG_RAW("        };\n")
26512
0
SLANG_RAW("    }\n")
26513
0
SLANG_RAW("\n")
26514
26515
0
    } // RW
26516
0
SLANG_RAW("#line 24010 \"hlsl.meta.slang\"")
26517
0
SLANG_RAW("\n")
26518
0
SLANG_RAW("\n")
26519
0
SLANG_RAW("    [ForceInline]\n")
26520
0
SLANG_RAW("    [__NoSideEffect]\n")
26521
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26522
0
SLANG_RAW("    static This Load<\n")
26523
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26524
0
SLANG_RAW("    >(T* buffer, uint element, uint stride)\n")
26525
0
SLANG_RAW("    {\n")
26526
0
SLANG_RAW("        let alignment = 16;\n")
26527
0
SLANG_RAW("        return spirv_asm\n")
26528
0
SLANG_RAW("        {\n")
26529
0
SLANG_RAW("            %pointer:$$T* = OpPtrAccessChain $buffer $element;\n")
26530
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned !alignment;\n")
26531
0
SLANG_RAW("        };\n")
26532
0
SLANG_RAW("    }\n")
26533
0
SLANG_RAW("\n")
26534
0
SLANG_RAW("    // TODO: make this function an intrinsic and support all types via the single intrinsic\n")
26535
0
SLANG_RAW("    [ForceInline]\n")
26536
0
SLANG_RAW("    [__NoSideEffect]\n")
26537
0
SLANG_RAW("    [require(cooperative_matrix, vk_mem_model)]\n")
26538
0
SLANG_RAW("    static This LoadCoherent<\n")
26539
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout\n")
26540
0
SLANG_RAW("    >(T* buffer, uint element, uint stride, constexpr MemoryScope memoryScope)\n")
26541
0
SLANG_RAW("    {\n")
26542
0
SLANG_RAW("        enableVMMDeviceScopeCapabilityIfNeeded(memoryScope);\n")
26543
0
SLANG_RAW("        let alignment = 16U;\n")
26544
0
SLANG_RAW("        const int32_t scope = (int32_t)memoryScope;\n")
26545
0
SLANG_RAW("        return spirv_asm\n")
26546
0
SLANG_RAW("        {\n")
26547
0
SLANG_RAW("            %pointer:$$T* = OpPtrAccessChain $buffer $element;\n")
26548
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned|MakePointerVisible|NonPrivatePointer !alignment $scope;\n")
26549
0
SLANG_RAW("        };\n")
26550
0
SLANG_RAW("    }\n")
26551
0
SLANG_RAW("\n")
26552
0
SLANG_RAW("    [ForceInline]\n")
26553
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26554
0
SLANG_RAW("    static This Load<\n")
26555
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26556
0
SLANG_RAW("        let V : int\n")
26557
0
SLANG_RAW("    >(__constref groupshared T[V] data, uint element, uint stride)\n")
26558
0
SLANG_RAW("    {\n")
26559
0
SLANG_RAW("        let alignment = 16U;\n")
26560
0
SLANG_RAW("        return spirv_asm\n")
26561
0
SLANG_RAW("        {\n")
26562
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$T;\n")
26563
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26564
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned !alignment;\n")
26565
0
SLANG_RAW("        };\n")
26566
0
SLANG_RAW("    }\n")
26567
0
SLANG_RAW("\n")
26568
0
SLANG_RAW("    [ForceInline]\n")
26569
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26570
0
SLANG_RAW("    static This Load<\n")
26571
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26572
0
SLANG_RAW("        U,\n")
26573
0
SLANG_RAW("        let V : int\n")
26574
0
SLANG_RAW("    >(__constref groupshared U[V] data, uint element, uint stride)\n")
26575
0
SLANG_RAW("    {\n")
26576
0
SLANG_RAW("        let alignment = 16U;\n")
26577
0
SLANG_RAW("        return spirv_asm\n")
26578
0
SLANG_RAW("        {\n")
26579
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$U;\n")
26580
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26581
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned !alignment;\n")
26582
0
SLANG_RAW("        };\n")
26583
0
SLANG_RAW("    }\n")
26584
0
SLANG_RAW("\n")
26585
0
SLANG_RAW("    [ForceInline]\n")
26586
0
SLANG_RAW("    [require(cooperative_matrix)]\n")
26587
0
SLANG_RAW("    static This Load<\n")
26588
0
SLANG_RAW("        let matrixLayout : CoopMatMatrixLayout,\n")
26589
0
SLANG_RAW("        U,\n")
26590
0
SLANG_RAW("        let V : int,\n")
26591
0
SLANG_RAW("        let L : int\n")
26592
0
SLANG_RAW("    >(__constref groupshared vector<U, L>[V] data, uint element, uint stride)\n")
26593
0
SLANG_RAW("    {\n")
26594
0
SLANG_RAW("        let alignment = 16U;\n")
26595
0
SLANG_RAW("        return spirv_asm\n")
26596
0
SLANG_RAW("        {\n")
26597
0
SLANG_RAW("            %workgroupPointerType = OpTypePointer Workgroup $$vector<U, L>;\n")
26598
0
SLANG_RAW("            %pointer:%workgroupPointerType = OpAccessChain &data $element;\n")
26599
0
SLANG_RAW("            result:$$CoopMat<T, S, M, N, R> = OpCooperativeMatrixLoadKHR %pointer $matrixLayout $stride Aligned !alignment;\n")
26600
0
SLANG_RAW("        };\n")
26601
0
SLANG_RAW("    }\n")
26602
0
SLANG_RAW("\n")
26603
0
SLANG_RAW("    //\n")
26604
0
SLANG_RAW("    // Arithmetic\n")
26605
0
SLANG_RAW("    //\n")
26606
0
SLANG_RAW("\n")
26607
0
SLANG_RAW("    __intrinsic_op(")
26608
0
SLANG_SPLICE(kIROp_Add
26609
0
)
26610
0
SLANG_RAW(")\n")
26611
0
SLANG_RAW("    This add(This other);\n")
26612
0
SLANG_RAW("\n")
26613
0
SLANG_RAW("    __intrinsic_op(")
26614
0
SLANG_SPLICE(kIROp_Sub
26615
0
)
26616
0
SLANG_RAW(")\n")
26617
0
SLANG_RAW("    This sub(This other);\n")
26618
0
SLANG_RAW("\n")
26619
0
SLANG_RAW("    __intrinsic_op(")
26620
0
SLANG_SPLICE(kIROp_Mul
26621
0
)
26622
0
SLANG_RAW(")\n")
26623
0
SLANG_RAW("    This mul(This other);\n")
26624
0
SLANG_RAW("\n")
26625
0
SLANG_RAW("    __intrinsic_op(")
26626
0
SLANG_SPLICE(kIROp_Div
26627
0
)
26628
0
SLANG_RAW(")\n")
26629
0
SLANG_RAW("    This div(This other);\n")
26630
0
SLANG_RAW("\n")
26631
0
SLANG_RAW("    __intrinsic_op(")
26632
0
SLANG_SPLICE(kIROp_Neg
26633
0
)
26634
0
SLANG_RAW(")\n")
26635
0
SLANG_RAW("    This neg();\n")
26636
0
SLANG_RAW("\n")
26637
0
SLANG_RAW("    This mod(This other)\n")
26638
0
SLANG_RAW("    {\n")
26639
0
SLANG_RAW("        This ret;\n")
26640
0
SLANG_RAW("        for (int i = 0; i < GetLength(); ++i)\n")
26641
0
SLANG_RAW("        {\n")
26642
0
SLANG_RAW("            ret[i] = this[i] % other[i];\n")
26643
0
SLANG_RAW("        }\n")
26644
0
SLANG_RAW("        return ret;\n")
26645
0
SLANG_RAW("    }\n")
26646
0
SLANG_RAW("\n")
26647
0
SLANG_RAW("    //\n")
26648
0
SLANG_RAW("    // Equality and ordering\n")
26649
0
SLANG_RAW("    //\n")
26650
0
SLANG_RAW("\n")
26651
0
SLANG_RAW("    bool equals(This other)\n")
26652
0
SLANG_RAW("    {\n")
26653
0
SLANG_RAW("        for (int i = 0; i < GetLength(); i++)\n")
26654
0
SLANG_RAW("        {\n")
26655
0
SLANG_RAW("            if (this[i] != other[i])\n")
26656
0
SLANG_RAW("            {\n")
26657
0
SLANG_RAW("                return false;\n")
26658
0
SLANG_RAW("            }\n")
26659
0
SLANG_RAW("        }\n")
26660
0
SLANG_RAW("        return true;\n")
26661
0
SLANG_RAW("    }\n")
26662
0
SLANG_RAW("\n")
26663
0
SLANG_RAW("    bool lessThan(This other)\n")
26664
0
SLANG_RAW("    {\n")
26665
0
SLANG_RAW("        for (int i = 0; i < GetLength(); i++)\n")
26666
0
SLANG_RAW("        {\n")
26667
0
SLANG_RAW("            if (this[i] < other[i])\n")
26668
0
SLANG_RAW("            {\n")
26669
0
SLANG_RAW("                return true;\n")
26670
0
SLANG_RAW("            }\n")
26671
0
SLANG_RAW("            else if (this[i] > other[i])\n")
26672
0
SLANG_RAW("            {\n")
26673
0
SLANG_RAW("                return false;\n")
26674
0
SLANG_RAW("            }\n")
26675
0
SLANG_RAW("        }\n")
26676
0
SLANG_RAW("        return false;\n")
26677
0
SLANG_RAW("    }\n")
26678
0
SLANG_RAW("\n")
26679
0
SLANG_RAW("    bool lessThanOrEquals(This other)\n")
26680
0
SLANG_RAW("    {\n")
26681
0
SLANG_RAW("        for (int i = 0; i < GetLength(); i++)\n")
26682
0
SLANG_RAW("        {\n")
26683
0
SLANG_RAW("            if (this[i] < other[i])\n")
26684
0
SLANG_RAW("            {\n")
26685
0
SLANG_RAW("                return true;\n")
26686
0
SLANG_RAW("            }\n")
26687
0
SLANG_RAW("            else if (this[i] > other[i])\n")
26688
0
SLANG_RAW("            {\n")
26689
0
SLANG_RAW("                return false;\n")
26690
0
SLANG_RAW("            }\n")
26691
0
SLANG_RAW("        }\n")
26692
0
SLANG_RAW("        return true;\n")
26693
0
SLANG_RAW("    }\n")
26694
0
SLANG_RAW("\n")
26695
0
SLANG_RAW("    //\n")
26696
0
SLANG_RAW("    // Load with TensorLayout and TensorView\n")
26697
0
SLANG_RAW("    //\n")
26698
0
SLANG_RAW("\n")
26699
26700
0
    StringBuilder tensorViewTypes;
26701
0
    StringBuilder tensorViewParams;
26702
0
    for (int j = 0; j < kMaxCoopMatTensorDimension; ++j)
26703
0
    {
26704
0
        tensorViewTypes << ", let p" << j << " : uint32_t = " << kMaxCoopMatTensorDimension;
26705
0
        tensorViewParams << ", p" << j;
26706
0
    }
26707
26708
0
    for (const char* RW : { "", "RW" })
26709
0
    {
26710
0
SLANG_RAW("#line 24188 \"hlsl.meta.slang\"")
26711
0
SLANG_RAW("\n")
26712
0
SLANG_RAW("\n")
26713
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26714
0
SLANG_RAW("    static This Load<\n")
26715
0
SLANG_RAW("        let Dim : uint32_t,\n")
26716
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26717
0
SLANG_RAW("    >(\n")
26718
0
SLANG_RAW("        ")
26719
0
SLANG_SPLICE(RW
26720
0
)
26721
0
SLANG_RAW("ByteAddressBuffer buffer,\n")
26722
0
SLANG_RAW("        uint element,\n")
26723
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout)\n")
26724
0
SLANG_RAW("    {\n")
26725
0
SLANG_RAW("        return __loadLayout<Dim, ClampMode>(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout);\n")
26726
0
SLANG_RAW("    }\n")
26727
0
SLANG_RAW("\n")
26728
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26729
0
SLANG_RAW("    static This Load<\n")
26730
0
SLANG_RAW("        let Dim : uint32_t,\n")
26731
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26732
0
SLANG_RAW("    >(\n")
26733
0
SLANG_RAW("        ")
26734
0
SLANG_SPLICE(RW
26735
0
)
26736
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26737
0
SLANG_RAW("        uint element,\n")
26738
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout)\n")
26739
0
SLANG_RAW("    {\n")
26740
0
SLANG_RAW("        return __loadLayout<Dim, ClampMode>(buffer, element, tensorLayout);\n")
26741
0
SLANG_RAW("    }\n")
26742
0
SLANG_RAW("\n")
26743
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26744
0
SLANG_RAW("    static This __loadLayout<\n")
26745
0
SLANG_RAW("        let Dim : uint32_t,\n")
26746
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26747
0
SLANG_RAW("    >(\n")
26748
0
SLANG_RAW("        ")
26749
0
SLANG_SPLICE(RW
26750
0
)
26751
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26752
0
SLANG_RAW("        uint element,\n")
26753
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout)\n")
26754
0
SLANG_RAW("    {\n")
26755
0
SLANG_RAW("        let zero = 0;\n")
26756
0
SLANG_RAW("        let alignment = 16U;\n")
26757
0
SLANG_RAW("\n")
26758
0
SLANG_RAW("        // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpCooperativeMatrixLoadTensorNV\n")
26759
0
SLANG_RAW("        This ret;\n")
26760
0
SLANG_RAW("        return spirv_asm\n")
26761
0
SLANG_RAW("        {\n")
26762
0
SLANG_RAW("            OpCapability CooperativeMatrixTensorAddressingNV;\n")
26763
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26764
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
26765
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
26766
0
SLANG_RAW("            result:$$This = OpCooperativeMatrixLoadTensorNV %pointer $ret $tensorLayout Aligned !alignment None;\n")
26767
0
SLANG_RAW("        };\n")
26768
0
SLANG_RAW("    }\n")
26769
0
SLANG_RAW("\n")
26770
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26771
0
SLANG_RAW("    static This Load<\n")
26772
0
SLANG_RAW("        let Dim : uint32_t,\n")
26773
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26774
0
SLANG_RAW("        let DimView : uint32_t,\n")
26775
0
SLANG_RAW("        let HasDimensions : bool\n")
26776
0
SLANG_RAW("        ")
26777
0
SLANG_SPLICE(tensorViewTypes
26778
0
)
26779
0
SLANG_RAW("\n")
26780
0
SLANG_RAW("    >(\n")
26781
0
SLANG_RAW("        ")
26782
0
SLANG_SPLICE(RW
26783
0
)
26784
0
SLANG_RAW("ByteAddressBuffer buffer,\n")
26785
0
SLANG_RAW("        uint element,\n")
26786
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26787
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
26788
0
SLANG_SPLICE(tensorViewParams
26789
0
)
26790
0
SLANG_RAW("> tensorView)\n")
26791
0
SLANG_RAW("    {\n")
26792
0
SLANG_RAW("        return __loadView<Dim, ClampMode, DimView, HasDimensions ")
26793
0
SLANG_SPLICE(tensorViewParams
26794
0
)
26795
0
SLANG_RAW(">(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout, tensorView);\n")
26796
0
SLANG_RAW("    }\n")
26797
0
SLANG_RAW("\n")
26798
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26799
0
SLANG_RAW("    static This Load<\n")
26800
0
SLANG_RAW("        let Dim : uint32_t,\n")
26801
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26802
0
SLANG_RAW("        let DimView : uint32_t,\n")
26803
0
SLANG_RAW("        let HasDimensions : bool\n")
26804
0
SLANG_RAW("        ")
26805
0
SLANG_SPLICE(tensorViewTypes
26806
0
)
26807
0
SLANG_RAW("\n")
26808
0
SLANG_RAW("    >(\n")
26809
0
SLANG_RAW("        ")
26810
0
SLANG_SPLICE(RW
26811
0
)
26812
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26813
0
SLANG_RAW("        uint element,\n")
26814
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26815
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
26816
0
SLANG_SPLICE(tensorViewParams
26817
0
)
26818
0
SLANG_RAW(" > tensorView)\n")
26819
0
SLANG_RAW("    {\n")
26820
0
SLANG_RAW("        return __loadView<Dim, ClampMode, DimView, HasDimensions ")
26821
0
SLANG_SPLICE(tensorViewParams
26822
0
)
26823
0
SLANG_RAW(">(buffer, element, tensorLayout, tensorView);\n")
26824
0
SLANG_RAW("    }\n")
26825
0
SLANG_RAW("\n")
26826
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
26827
0
SLANG_RAW("    static This __loadView<\n")
26828
0
SLANG_RAW("        let Dim : uint32_t,\n")
26829
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26830
0
SLANG_RAW("        let DimView : uint32_t,\n")
26831
0
SLANG_RAW("        let HasDimensions : bool\n")
26832
0
SLANG_RAW("        ")
26833
0
SLANG_SPLICE(tensorViewTypes
26834
0
)
26835
0
SLANG_RAW("\n")
26836
0
SLANG_RAW("    >(\n")
26837
0
SLANG_RAW("        ")
26838
0
SLANG_SPLICE(RW
26839
0
)
26840
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26841
0
SLANG_RAW("        uint element,\n")
26842
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26843
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
26844
0
SLANG_SPLICE(tensorViewParams
26845
0
)
26846
0
SLANG_RAW(" > tensorView)\n")
26847
0
SLANG_RAW("    {\n")
26848
0
SLANG_RAW("        let zero = 0;\n")
26849
0
SLANG_RAW("        let alignment = 16U;\n")
26850
0
SLANG_RAW("\n")
26851
0
SLANG_RAW("        // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpCooperativeMatrixLoadTensorNV\n")
26852
0
SLANG_RAW("        This ret;\n")
26853
0
SLANG_RAW("        return spirv_asm\n")
26854
0
SLANG_RAW("        {\n")
26855
0
SLANG_RAW("            OpCapability CooperativeMatrixTensorAddressingNV;\n")
26856
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26857
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
26858
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
26859
0
SLANG_RAW("            result:$$This = OpCooperativeMatrixLoadTensorNV %pointer $ret $tensorLayout Aligned !alignment TensorView $tensorView;\n")
26860
0
SLANG_RAW("        };\n")
26861
0
SLANG_RAW("    }\n")
26862
0
SLANG_RAW("\n")
26863
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26864
0
SLANG_RAW("    static This Load<\n")
26865
0
SLANG_RAW("        U,\n")
26866
0
SLANG_RAW("        let Dim : uint32_t,\n")
26867
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26868
0
SLANG_RAW("    >(\n")
26869
0
SLANG_RAW("        ")
26870
0
SLANG_SPLICE(RW
26871
0
)
26872
0
SLANG_RAW("ByteAddressBuffer buffer,\n")
26873
0
SLANG_RAW("        uint element,\n")
26874
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26875
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
26876
0
SLANG_RAW("    {\n")
26877
0
SLANG_RAW("        return __loadLayoutDecode<U, Dim, ClampMode>(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout, decodeFunc);\n")
26878
0
SLANG_RAW("    }\n")
26879
0
SLANG_RAW("\n")
26880
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26881
0
SLANG_RAW("    static This Load<\n")
26882
0
SLANG_RAW("        U,\n")
26883
0
SLANG_RAW("        let Dim : uint32_t,\n")
26884
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26885
0
SLANG_RAW("    >(\n")
26886
0
SLANG_RAW("        ")
26887
0
SLANG_SPLICE(RW
26888
0
)
26889
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26890
0
SLANG_RAW("        uint element,\n")
26891
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26892
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
26893
0
SLANG_RAW("    {\n")
26894
0
SLANG_RAW("        return __loadLayoutDecode<U, Dim, ClampMode>(buffer, element, tensorLayout, decodeFunc);\n")
26895
0
SLANG_RAW("    }\n")
26896
0
SLANG_RAW("\n")
26897
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26898
0
SLANG_RAW("    static This __loadLayoutDecode<\n")
26899
0
SLANG_RAW("        U,\n")
26900
0
SLANG_RAW("        let Dim : uint32_t,\n")
26901
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
26902
0
SLANG_RAW("    >(\n")
26903
0
SLANG_RAW("        ")
26904
0
SLANG_SPLICE(RW
26905
0
)
26906
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26907
0
SLANG_RAW("        uint element,\n")
26908
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26909
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
26910
0
SLANG_RAW("    {\n")
26911
0
SLANG_RAW("        let zero = 0;\n")
26912
0
SLANG_RAW("        let alignment = 16U;\n")
26913
0
SLANG_RAW("\n")
26914
0
SLANG_RAW("        // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpCooperativeMatrixLoadTensorNV\n")
26915
0
SLANG_RAW("        This ret;\n")
26916
0
SLANG_RAW("        return spirv_asm\n")
26917
0
SLANG_RAW("        {\n")
26918
0
SLANG_RAW("            OpCapability CooperativeMatrixBlockLoadsNV;\n")
26919
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
26920
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
26921
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
26922
0
SLANG_RAW("            result:$$This = OpCooperativeMatrixLoadTensorNV %pointer $ret $tensorLayout Aligned !alignment DecodeFunc $decodeFunc;\n")
26923
0
SLANG_RAW("        };\n")
26924
0
SLANG_RAW("    }\n")
26925
0
SLANG_RAW("\n")
26926
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26927
0
SLANG_RAW("    static This Load<\n")
26928
0
SLANG_RAW("        U,\n")
26929
0
SLANG_RAW("        let Dim : uint32_t,\n")
26930
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26931
0
SLANG_RAW("        let DimView : uint32_t,\n")
26932
0
SLANG_RAW("        let HasDimensions : bool\n")
26933
0
SLANG_RAW("        ")
26934
0
SLANG_SPLICE(tensorViewTypes
26935
0
)
26936
0
SLANG_RAW("\n")
26937
0
SLANG_RAW("    >(\n")
26938
0
SLANG_RAW("        ")
26939
0
SLANG_SPLICE(RW
26940
0
)
26941
0
SLANG_RAW("ByteAddressBuffer buffer,\n")
26942
0
SLANG_RAW("        uint element,\n")
26943
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26944
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
26945
0
SLANG_SPLICE(tensorViewParams
26946
0
)
26947
0
SLANG_RAW("> tensorView,\n")
26948
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
26949
0
SLANG_RAW("    {\n")
26950
0
SLANG_RAW("        return __loadViewDecode<U, Dim, ClampMode, DimView, HasDimensions ")
26951
0
SLANG_SPLICE(tensorViewParams
26952
0
)
26953
0
SLANG_RAW(">(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout, tensorView, decodeFunc);\n")
26954
0
SLANG_RAW("    }\n")
26955
0
SLANG_RAW("\n")
26956
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26957
0
SLANG_RAW("    static This Load<\n")
26958
0
SLANG_RAW("        U,\n")
26959
0
SLANG_RAW("        let Dim : uint32_t,\n")
26960
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26961
0
SLANG_RAW("        let DimView : uint32_t,\n")
26962
0
SLANG_RAW("        let HasDimensions : bool\n")
26963
0
SLANG_RAW("        ")
26964
0
SLANG_SPLICE(tensorViewTypes
26965
0
)
26966
0
SLANG_RAW("\n")
26967
0
SLANG_RAW("    >(\n")
26968
0
SLANG_RAW("        ")
26969
0
SLANG_SPLICE(RW
26970
0
)
26971
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
26972
0
SLANG_RAW("        uint element,\n")
26973
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
26974
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
26975
0
SLANG_SPLICE(tensorViewParams
26976
0
)
26977
0
SLANG_RAW("> tensorView,\n")
26978
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
26979
0
SLANG_RAW("    {\n")
26980
0
SLANG_RAW("        return __loadViewDecode<U, Dim, ClampMode, DimView, HasDimensions ")
26981
0
SLANG_SPLICE(tensorViewParams
26982
0
)
26983
0
SLANG_RAW(">(buffer, element, tensorLayout, tensorView, decodeFunc);\n")
26984
0
SLANG_RAW("    }\n")
26985
0
SLANG_RAW("\n")
26986
0
SLANG_RAW("    [require(cooperative_matrix_block_load)]\n")
26987
0
SLANG_RAW("    static This __loadViewDecode<\n")
26988
0
SLANG_RAW("        U,\n")
26989
0
SLANG_RAW("        let Dim : uint32_t,\n")
26990
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
26991
0
SLANG_RAW("        let DimView : uint32_t,\n")
26992
0
SLANG_RAW("        let HasDimensions : bool\n")
26993
0
SLANG_RAW("        ")
26994
0
SLANG_SPLICE(tensorViewTypes
26995
0
)
26996
0
SLANG_RAW("\n")
26997
0
SLANG_RAW("    >(\n")
26998
0
SLANG_RAW("        ")
26999
0
SLANG_SPLICE(RW
27000
0
)
27001
0
SLANG_RAW("StructuredBuffer<T> buffer,\n")
27002
0
SLANG_RAW("        uint element,\n")
27003
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
27004
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
27005
0
SLANG_SPLICE(tensorViewParams
27006
0
)
27007
0
SLANG_RAW("> tensorView,\n")
27008
0
SLANG_RAW("        functype(U*, uint32_t[Dim], uint32_t[Dim]) -> T decodeFunc)\n")
27009
0
SLANG_RAW("    {\n")
27010
0
SLANG_RAW("        let zero = 0;\n")
27011
0
SLANG_RAW("        let alignment = 16U;\n")
27012
0
SLANG_RAW("\n")
27013
0
SLANG_RAW("        // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpCooperativeMatrixLoadTensorNV\n")
27014
0
SLANG_RAW("        This ret;\n")
27015
0
SLANG_RAW("        return spirv_asm\n")
27016
0
SLANG_RAW("        {\n")
27017
0
SLANG_RAW("            OpCapability CooperativeMatrixTensorAddressingNV;\n")
27018
0
SLANG_RAW("            OpCapability CooperativeMatrixBlockLoadsNV;\n")
27019
0
SLANG_RAW("            OpExtension \"SPV_NV_cooperative_matrix2\";\n")
27020
0
SLANG_RAW("            %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
27021
0
SLANG_RAW("            %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
27022
0
SLANG_RAW("            result:$$This = OpCooperativeMatrixLoadTensorNV %pointer $ret $tensorLayout Aligned !alignment TensorView|DecodeFunc $tensorView $decodeFunc;\n")
27023
0
SLANG_RAW("        };\n")
27024
0
SLANG_RAW("    }\n")
27025
0
SLANG_RAW("\n")
27026
27027
0
    } // RW
27028
0
SLANG_RAW("#line 24421 \"hlsl.meta.slang\"")
27029
0
SLANG_RAW("\n")
27030
0
SLANG_RAW("\n")
27031
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
27032
0
SLANG_RAW("    void Store<\n")
27033
0
SLANG_RAW("        let Dim : uint32_t,\n")
27034
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
27035
0
SLANG_RAW("    >(\n")
27036
0
SLANG_RAW("        RWByteAddressBuffer buffer,\n")
27037
0
SLANG_RAW("        uint element,\n")
27038
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout)\n")
27039
0
SLANG_RAW("    {\n")
27040
0
SLANG_RAW("        Store(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout);\n")
27041
0
SLANG_RAW("    }\n")
27042
0
SLANG_RAW("\n")
27043
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
27044
0
SLANG_RAW("    void Store<\n")
27045
0
SLANG_RAW("        let Dim : uint32_t,\n")
27046
0
SLANG_RAW("        let ClampMode : CoopMatClampMode\n")
27047
0
SLANG_RAW("    >(\n")
27048
0
SLANG_RAW("        RWStructuredBuffer<T> buffer,\n")
27049
0
SLANG_RAW("        uint element,\n")
27050
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout)\n")
27051
0
SLANG_RAW("    {\n")
27052
0
SLANG_RAW("        let zero = 0;\n")
27053
0
SLANG_RAW("        let alignment = 16U;\n")
27054
0
SLANG_RAW("\n")
27055
0
SLANG_RAW("        __target_switch\n")
27056
0
SLANG_RAW("        {\n")
27057
0
SLANG_RAW("        case spirv:\n")
27058
0
SLANG_RAW("            spirv_asm\n")
27059
0
SLANG_RAW("            {\n")
27060
0
SLANG_RAW("                OpCapability CooperativeMatrixTensorAddressingNV;\n")
27061
0
SLANG_RAW("                OpExtension \"SPV_NV_cooperative_matrix2\";\n")
27062
0
SLANG_RAW("                %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
27063
0
SLANG_RAW("                %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
27064
0
SLANG_RAW("                OpCooperativeMatrixStoreTensorNV %pointer $this $tensorLayout Aligned !alignment None;\n")
27065
0
SLANG_RAW("            };\n")
27066
0
SLANG_RAW("        }\n")
27067
0
SLANG_RAW("    }\n")
27068
0
SLANG_RAW("\n")
27069
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
27070
0
SLANG_RAW("    void Store<\n")
27071
0
SLANG_RAW("        let Dim : uint32_t,\n")
27072
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
27073
0
SLANG_RAW("        let DimView : uint32_t,\n")
27074
0
SLANG_RAW("        let HasDimensions : bool\n")
27075
0
SLANG_RAW("        ")
27076
0
SLANG_SPLICE(tensorViewTypes
27077
0
)
27078
0
SLANG_RAW("\n")
27079
0
SLANG_RAW("    >(\n")
27080
0
SLANG_RAW("        RWByteAddressBuffer buffer,\n")
27081
0
SLANG_RAW("        uint element,\n")
27082
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
27083
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
27084
0
SLANG_SPLICE(tensorViewParams
27085
0
)
27086
0
SLANG_RAW("> tensorView)\n")
27087
0
SLANG_RAW("    {\n")
27088
0
SLANG_RAW("        Store(__getEquivalentStructuredBuffer<T>(buffer), element, tensorLayout, tensorView);\n")
27089
0
SLANG_RAW("    }\n")
27090
0
SLANG_RAW("\n")
27091
0
SLANG_RAW("    [require(cooperative_matrix_tensor_addressing)]\n")
27092
0
SLANG_RAW("    void Store<\n")
27093
0
SLANG_RAW("        let Dim : uint32_t,\n")
27094
0
SLANG_RAW("        let ClampMode : CoopMatClampMode,\n")
27095
0
SLANG_RAW("        let DimView : uint32_t,\n")
27096
0
SLANG_RAW("        let HasDimensions : bool\n")
27097
0
SLANG_RAW("        ")
27098
0
SLANG_SPLICE(tensorViewTypes
27099
0
)
27100
0
SLANG_RAW("\n")
27101
0
SLANG_RAW("    >(\n")
27102
0
SLANG_RAW("        RWStructuredBuffer<T> buffer,\n")
27103
0
SLANG_RAW("        uint element,\n")
27104
0
SLANG_RAW("        TensorLayout<Dim, ClampMode> tensorLayout,\n")
27105
0
SLANG_RAW("        TensorView<DimView, HasDimensions ")
27106
0
SLANG_SPLICE(tensorViewParams
27107
0
)
27108
0
SLANG_RAW("> tensorView)\n")
27109
0
SLANG_RAW("    {\n")
27110
0
SLANG_RAW("        let zero = 0;\n")
27111
0
SLANG_RAW("        let alignment = 16U;\n")
27112
0
SLANG_RAW("\n")
27113
0
SLANG_RAW("        __target_switch\n")
27114
0
SLANG_RAW("        {\n")
27115
0
SLANG_RAW("        case spirv:\n")
27116
0
SLANG_RAW("            spirv_asm\n")
27117
0
SLANG_RAW("            {\n")
27118
0
SLANG_RAW("                OpCapability CooperativeMatrixTensorAddressingNV;\n")
27119
0
SLANG_RAW("                OpExtension \"SPV_NV_cooperative_matrix2\";\n")
27120
0
SLANG_RAW("                %storagePointerType = OpTypePointer StorageBuffer $$T;\n")
27121
0
SLANG_RAW("                %pointer:%storagePointerType = OpAccessChain $buffer $zero $element;\n")
27122
0
SLANG_RAW("                OpCooperativeMatrixStoreTensorNV %pointer $this $tensorLayout Aligned !alignment TensorView $tensorView;\n")
27123
0
SLANG_RAW("            };\n")
27124
0
SLANG_RAW("        }\n")
27125
0
SLANG_RAW("    }\n")
27126
0
SLANG_RAW("\n")
27127
0
SLANG_RAW("} // struct CoopMat\n")
27128
0
SLANG_RAW("\n")
27129
0
SLANG_RAW("\n")
27130
0
SLANG_RAW("//\n")
27131
0
SLANG_RAW("// Convenience loading functions for cooperative matrices which infer the\n")
27132
0
SLANG_RAW("// element type for structured buffers, pointers and groupshared arrays.\n")
27133
0
SLANG_RAW("//\n")
27134
0
SLANG_RAW("\n")
27135
0
SLANG_RAW("[ForceInline]\n")
27136
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27137
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27138
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27139
0
SLANG_RAW("    let S : MemoryScope,\n")
27140
0
SLANG_RAW("    let M : int,\n")
27141
0
SLANG_RAW("    let N : int,\n")
27142
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27143
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27144
0
SLANG_RAW(">(\n")
27145
0
SLANG_RAW("    ByteAddressBuffer buffer,\n")
27146
0
SLANG_RAW("    uint element,\n")
27147
0
SLANG_RAW("    uint stride)\n")
27148
0
SLANG_RAW("{\n")
27149
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(__getEquivalentStructuredBuffer<T>(buffer), element, stride);\n")
27150
0
SLANG_RAW("}\n")
27151
0
SLANG_RAW("\n")
27152
0
SLANG_RAW("[ForceInline]\n")
27153
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27154
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27155
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27156
0
SLANG_RAW("    let S : MemoryScope,\n")
27157
0
SLANG_RAW("    let M : int,\n")
27158
0
SLANG_RAW("    let N : int,\n")
27159
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27160
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27161
0
SLANG_RAW(">(\n")
27162
0
SLANG_RAW("    RWByteAddressBuffer buffer,\n")
27163
0
SLANG_RAW("    uint element,\n")
27164
0
SLANG_RAW("    uint stride)\n")
27165
0
SLANG_RAW("{\n")
27166
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(__getEquivalentStructuredBuffer<T>(buffer), element, stride);\n")
27167
0
SLANG_RAW("}\n")
27168
0
SLANG_RAW("\n")
27169
0
SLANG_RAW("[ForceInline]\n")
27170
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27171
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27172
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27173
0
SLANG_RAW("    let S : MemoryScope,\n")
27174
0
SLANG_RAW("    let M : int,\n")
27175
0
SLANG_RAW("    let N : int,\n")
27176
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27177
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27178
0
SLANG_RAW(">(\n")
27179
0
SLANG_RAW("    StructuredBuffer<T> buffer,\n")
27180
0
SLANG_RAW("    uint element,\n")
27181
0
SLANG_RAW("    uint stride)\n")
27182
0
SLANG_RAW("{\n")
27183
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(buffer, element, stride);\n")
27184
0
SLANG_RAW("}\n")
27185
0
SLANG_RAW("\n")
27186
0
SLANG_RAW("[ForceInline]\n")
27187
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27188
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27189
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27190
0
SLANG_RAW("    let S : MemoryScope,\n")
27191
0
SLANG_RAW("    let M : int,\n")
27192
0
SLANG_RAW("    let N : int,\n")
27193
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27194
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27195
0
SLANG_RAW(">(\n")
27196
0
SLANG_RAW("    RWStructuredBuffer<T> buffer,\n")
27197
0
SLANG_RAW("    uint element,\n")
27198
0
SLANG_RAW("    uint stride)\n")
27199
0
SLANG_RAW("{\n")
27200
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(buffer, element, stride);\n")
27201
0
SLANG_RAW("}\n")
27202
0
SLANG_RAW("\n")
27203
0
SLANG_RAW("[ForceInline]\n")
27204
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27205
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27206
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27207
0
SLANG_RAW("    let S : MemoryScope,\n")
27208
0
SLANG_RAW("    let M : int,\n")
27209
0
SLANG_RAW("    let N : int,\n")
27210
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27211
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27212
0
SLANG_RAW(">(\n")
27213
0
SLANG_RAW("    T* buffer,\n")
27214
0
SLANG_RAW("    uint element,\n")
27215
0
SLANG_RAW("    uint stride)\n")
27216
0
SLANG_RAW("{\n")
27217
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(buffer, element, stride);\n")
27218
0
SLANG_RAW("}\n")
27219
0
SLANG_RAW("\n")
27220
0
SLANG_RAW("[ForceInline]\n")
27221
0
SLANG_RAW("[require(cooperative_matrix, vk_mem_model)]\n")
27222
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoadCoherent<\n")
27223
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27224
0
SLANG_RAW("    let S : MemoryScope,\n")
27225
0
SLANG_RAW("    let M : int,\n")
27226
0
SLANG_RAW("    let N : int,\n")
27227
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27228
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout\n")
27229
0
SLANG_RAW(">(\n")
27230
0
SLANG_RAW("    T* buffer,\n")
27231
0
SLANG_RAW("    uint element,\n")
27232
0
SLANG_RAW("    uint stride,\n")
27233
0
SLANG_RAW("    constexpr MemoryScope memoryScope)\n")
27234
0
SLANG_RAW("{\n")
27235
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.LoadCoherent<matrixLayout>(buffer, element, stride, memoryScope);\n")
27236
0
SLANG_RAW("}\n")
27237
0
SLANG_RAW("\n")
27238
0
SLANG_RAW("[ForceInline]\n")
27239
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27240
0
SLANG_RAW("CoopMat<T, S, M, N, R> coopMatLoad<\n")
27241
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27242
0
SLANG_RAW("    let S : MemoryScope,\n")
27243
0
SLANG_RAW("    let M : int,\n")
27244
0
SLANG_RAW("    let N : int,\n")
27245
0
SLANG_RAW("    let R : CoopMatMatrixUse,\n")
27246
0
SLANG_RAW("    let matrixLayout : CoopMatMatrixLayout,\n")
27247
0
SLANG_RAW("    let U : int\n")
27248
0
SLANG_RAW(">(\n")
27249
0
SLANG_RAW("    __constref groupshared T[U] data,\n")
27250
0
SLANG_RAW("    uint element,\n")
27251
0
SLANG_RAW("    uint stride)\n")
27252
0
SLANG_RAW("{\n")
27253
0
SLANG_RAW("    return CoopMat<T, S, M, N, R>.Load<matrixLayout>(data, element, stride);\n")
27254
0
SLANG_RAW("}\n")
27255
0
SLANG_RAW("\n")
27256
0
SLANG_RAW("\n")
27257
0
SLANG_RAW("//\n")
27258
0
SLANG_RAW("// Cooperative Matrix casting\n")
27259
0
SLANG_RAW("//\n")
27260
0
SLANG_RAW("\n")
27261
0
SLANG_RAW("[require(cooperative_matrix_conversion)]\n")
27262
0
SLANG_RAW("__intrinsic_op(")
27263
0
SLANG_SPLICE(kIROp_IntCast
27264
0
)
27265
0
SLANG_RAW(")\n")
27266
0
SLANG_RAW("CoopMat<T,S,M,N,R> __int_cast<\n")
27267
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27268
0
SLANG_RAW("    U : __BuiltinArithmeticType,\n")
27269
0
SLANG_RAW("    let S : MemoryScope,\n")
27270
0
SLANG_RAW("    let M : int,\n")
27271
0
SLANG_RAW("    let N : int,\n")
27272
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27273
0
SLANG_RAW(">(CoopMat<U,S,M,N,R> val);\n")
27274
0
SLANG_RAW("\n")
27275
0
SLANG_RAW("[require(cooperative_matrix_conversion)]\n")
27276
0
SLANG_RAW("__intrinsic_op(")
27277
0
SLANG_SPLICE(kIROp_FloatCast
27278
0
)
27279
0
SLANG_RAW(")\n")
27280
0
SLANG_RAW("CoopMat<T,S,M,N,R> __real_cast<\n")
27281
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27282
0
SLANG_RAW("    U : __BuiltinArithmeticType,\n")
27283
0
SLANG_RAW("    let S : MemoryScope,\n")
27284
0
SLANG_RAW("    let M : int,\n")
27285
0
SLANG_RAW("    let N : int,\n")
27286
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27287
0
SLANG_RAW(">(CoopMat<U,S,M,N,R> val);\n")
27288
0
SLANG_RAW("\n")
27289
0
SLANG_RAW("[require(cooperative_matrix_conversion)]\n")
27290
0
SLANG_RAW("__intrinsic_op(")
27291
0
SLANG_SPLICE(kIROp_CastIntToFloat
27292
0
)
27293
0
SLANG_RAW(")\n")
27294
0
SLANG_RAW("CoopMat<T,S,M,N,R> __int_to_float_cast<\n")
27295
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27296
0
SLANG_RAW("    U : __BuiltinArithmeticType,\n")
27297
0
SLANG_RAW("    let S : MemoryScope,\n")
27298
0
SLANG_RAW("    let M : int,\n")
27299
0
SLANG_RAW("    let N : int,\n")
27300
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27301
0
SLANG_RAW(">(CoopMat<U,S,M,N,R> val);\n")
27302
0
SLANG_RAW("\n")
27303
0
SLANG_RAW("[require(cooperative_matrix_conversion)]\n")
27304
0
SLANG_RAW("__intrinsic_op(")
27305
0
SLANG_SPLICE(kIROp_CastFloatToInt
27306
0
)
27307
0
SLANG_RAW(")\n")
27308
0
SLANG_RAW("CoopMat<T,S,M,N,R> __float_to_int_cast<\n")
27309
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27310
0
SLANG_RAW("    U : __BuiltinArithmeticType,\n")
27311
0
SLANG_RAW("    let S : MemoryScope,\n")
27312
0
SLANG_RAW("    let M : int,\n")
27313
0
SLANG_RAW("    let N : int,\n")
27314
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27315
0
SLANG_RAW(">(CoopMat<U,S,M,N,R> val);\n")
27316
0
SLANG_RAW("\n")
27317
0
SLANG_RAW("//\n")
27318
0
SLANG_RAW("// Cooperative Matrix multiplication with scalar\n")
27319
0
SLANG_RAW("//\n")
27320
0
SLANG_RAW("\n")
27321
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27322
0
SLANG_RAW("CoopMat<T, S, M, N, R> operator *<\n")
27323
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27324
0
SLANG_RAW("    let S : MemoryScope,\n")
27325
0
SLANG_RAW("    let M : int,\n")
27326
0
SLANG_RAW("    let N : int,\n")
27327
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27328
0
SLANG_RAW(">(CoopMat<T, S, M, N, R> lhs, const T rhs)\n")
27329
0
SLANG_RAW("{\n")
27330
0
SLANG_RAW("    return spirv_asm\n")
27331
0
SLANG_RAW("    {\n")
27332
0
SLANG_RAW("        result:$$CoopMat<T, S, M, N, R> = OpMatrixTimesScalar $lhs $rhs;\n")
27333
0
SLANG_RAW("    };\n")
27334
0
SLANG_RAW("}\n")
27335
0
SLANG_RAW("\n")
27336
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27337
0
SLANG_RAW("CoopMat<T, S, M, N, R> operator *<\n")
27338
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27339
0
SLANG_RAW("    let S : MemoryScope,\n")
27340
0
SLANG_RAW("    let M : int,\n")
27341
0
SLANG_RAW("    let N : int,\n")
27342
0
SLANG_RAW("    let R : CoopMatMatrixUse\n")
27343
0
SLANG_RAW(">(const T lhs, CoopMat<T, S, M, N, R> rhs)\n")
27344
0
SLANG_RAW("{\n")
27345
0
SLANG_RAW("    return rhs * lhs;\n")
27346
0
SLANG_RAW("}\n")
27347
0
SLANG_RAW("\n")
27348
0
SLANG_RAW("//\n")
27349
0
SLANG_RAW("// Cooperative Matrix Multiply-Accumulate\n")
27350
0
SLANG_RAW("//\n")
27351
0
SLANG_RAW("\n")
27352
0
SLANG_RAW("[require(cooperative_matrix)]\n")
27353
0
SLANG_RAW("CoopMat<T, S, M, N, CoopMatMatrixUse.MatrixAccumulator> coopMatMulAdd<\n")
27354
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27355
0
SLANG_RAW("    let saturatingAccumulation : bool,\n")
27356
0
SLANG_RAW("    U : __BuiltinArithmeticType,\n")
27357
0
SLANG_RAW("    V : __BuiltinArithmeticType,\n")
27358
0
SLANG_RAW("    W : __BuiltinArithmeticType,\n")
27359
0
SLANG_RAW("    let S : MemoryScope,\n")
27360
0
SLANG_RAW("    let M : int,\n")
27361
0
SLANG_RAW("    let K : int,\n")
27362
0
SLANG_RAW("    let N : int\n")
27363
0
SLANG_RAW(">(\n")
27364
0
SLANG_RAW("    CoopMat<U, S, M, K, CoopMatMatrixUse.MatrixA> matA,\n")
27365
0
SLANG_RAW("    CoopMat<V, S, K, N, CoopMatMatrixUse.MatrixB> matB,\n")
27366
0
SLANG_RAW("    CoopMat<W, S, M, N, CoopMatMatrixUse.MatrixAccumulator> matC)\n")
27367
0
SLANG_RAW("{\n")
27368
0
SLANG_RAW("    // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_cooperative_matrix.asciidoc#3x-cooperative-matrix-operands\n")
27369
0
SLANG_RAW("    int operands = 0; // NoneKHR\n")
27370
0
SLANG_RAW("    if (__isSignedInt<U>())\n")
27371
0
SLANG_RAW("    {\n")
27372
0
SLANG_RAW("        operands |= 0x01; // MatrixASignedComponentsKHR\n")
27373
0
SLANG_RAW("    }\n")
27374
0
SLANG_RAW("    if (__isSignedInt<V>())\n")
27375
0
SLANG_RAW("    {\n")
27376
0
SLANG_RAW("        operands |= 0x02; // MatrixBSignedComponentsKHR\n")
27377
0
SLANG_RAW("    }\n")
27378
0
SLANG_RAW("    if (__isSignedInt<W>())\n")
27379
0
SLANG_RAW("    {\n")
27380
0
SLANG_RAW("        operands |= 0x04; // MatrixCSignedComponentsKHR\n")
27381
0
SLANG_RAW("    }\n")
27382
0
SLANG_RAW("    if (__isSignedInt<T>())\n")
27383
0
SLANG_RAW("    {\n")
27384
0
SLANG_RAW("        operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
27385
0
SLANG_RAW("    }\n")
27386
0
SLANG_RAW("    if (saturatingAccumulation)\n")
27387
0
SLANG_RAW("    {\n")
27388
0
SLANG_RAW("        operands |= 0x10; // SaturatingAccumulationKHR\n")
27389
0
SLANG_RAW("    }\n")
27390
0
SLANG_RAW("\n")
27391
0
SLANG_RAW("    return spirv_asm\n")
27392
0
SLANG_RAW("    {\n")
27393
0
SLANG_RAW("        result:$$CoopMat<T, S, M, N, CoopMatMatrixUse.MatrixAccumulator> = OpCooperativeMatrixMulAddKHR $matA $matB $matC !operands;\n")
27394
0
SLANG_RAW("    };\n")
27395
0
SLANG_RAW("}\n")
27396
0
SLANG_RAW("\n")
27397
0
SLANG_RAW("extension<\n")
27398
0
SLANG_RAW("    T : __BuiltinArithmeticType,\n")
27399
0
SLANG_RAW("    let S : MemoryScope,\n")
27400
0
SLANG_RAW("    let M : int,\n")
27401
0
SLANG_RAW("    let N : int,\n")
27402
0
SLANG_RAW("    let R : linalg.CoopMatMatrixUse,\n")
27403
0
SLANG_RAW("    each Ts : __BuiltinArithmeticType\n")
27404
0
SLANG_RAW("> Tuple<linalg.CoopMat<T, S, M, N, R>, expand linalg.CoopMat<each Ts, S, M, N, R>>\n")
27405
0
SLANG_RAW("{\n")
27406
0
SLANG_RAW("    __intrinsic_op(")
27407
0
SLANG_SPLICE(kIROp_CoopMatMapElementIFunc
27408
0
)
27409
0
SLANG_RAW(")\n")
27410
0
SLANG_RAW("    CoopMat<T, S, M, N, R> MapElement(functype(uint32_t, uint32_t, T, expand each Ts)->T mapOp);\n")
27411
0
SLANG_RAW("\n")
27412
0
SLANG_RAW("    __intrinsic_op(")
27413
0
SLANG_SPLICE(kIROp_CoopMatMapElementIFunc
27414
0
)
27415
0
SLANG_RAW(")\n")
27416
0
SLANG_RAW("    internal static CoopMat<T, S, M, N, R> __MapElement<\n")
27417
0
SLANG_RAW("        TOperator,\n")
27418
0
SLANG_RAW("        TFunc : IFunc<T, uint32_t, uint32_t, T, expand each Ts>\n")
27419
0
SLANG_RAW("    >(This tuple, TOperator mapOp, TFunc mapObj);\n")
27420
0
SLANG_RAW("\n")
27421
0
SLANG_RAW("    [ForceInline]\n")
27422
0
SLANG_RAW("    CoopMat<T, S, M, N, R> MapElement<\n")
27423
0
SLANG_RAW("        TFunc : IFunc<T, uint32_t, uint32_t, T, expand each Ts>\n")
27424
0
SLANG_RAW("    >(TFunc mapOp)\n")
27425
0
SLANG_RAW("    {\n")
27426
0
SLANG_RAW("        return __MapElement(this, mapOp.operator(), mapOp);\n")
27427
0
SLANG_RAW("    }\n")
27428
0
SLANG_RAW("};\n")
27429
0
SLANG_RAW("\n")
27430
0
SLANG_RAW("} // namespace linalg\n")
27431
0
SLANG_RAW("\n")
27432
0
SLANG_RAW("\n")
27433
0
SLANG_RAW("//\n")
27434
0
SLANG_RAW("// Cooperative Vector\n")
27435
0
SLANG_RAW("//\n")
27436
0
SLANG_RAW("\n")
27437
0
SLANG_RAW("/// Represents a Cooperative Vector type that is for matrix-vector multiplication that\n")
27438
0
SLANG_RAW("/// can take an advantage of the hardware acceleration. It can be used for evaluations\n")
27439
0
SLANG_RAW("/// of neural network in graphics and compute pipeline.\n")
27440
0
SLANG_RAW("/// @param T The element type of the CoopVec.\n")
27441
0
SLANG_RAW("/// @param N The vector size.\n")
27442
0
SLANG_RAW("__intrinsic_type(")
27443
0
SLANG_SPLICE(kIROp_CoopVectorType
27444
0
)
27445
0
SLANG_RAW(")\n")
27446
0
SLANG_RAW("[require(cooperative_vector)]\n")
27447
0
SLANG_RAW("struct CoopVec<T : __BuiltinArithmeticType, let N : int> : IArray<T>, IArithmetic\n")
27448
0
SLANG_RAW("{\n")
27449
0
SLANG_RAW("    //\n")
27450
0
SLANG_RAW("    // Initialization\n")
27451
0
SLANG_RAW("    //\n")
27452
0
SLANG_RAW("\n")
27453
0
SLANG_RAW("    [ForceInline]\n")
27454
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27455
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27456
0
SLANG_RAW("    __init()\n")
27457
0
SLANG_RAW("    {\n")
27458
0
SLANG_RAW("        this = CoopVec<T, N>(T(0));\n")
27459
0
SLANG_RAW("    }\n")
27460
0
SLANG_RAW("\n")
27461
0
SLANG_RAW("    [ForceInline]\n")
27462
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27463
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27464
0
SLANG_RAW("    __init(T t)\n")
27465
0
SLANG_RAW("    {\n")
27466
0
SLANG_RAW("        this.fill(t);\n")
27467
0
SLANG_RAW("    }\n")
27468
0
SLANG_RAW("\n")
27469
0
SLANG_RAW("    [ForceInline]\n")
27470
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27471
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27472
0
SLANG_RAW("    [require(optix_coopvec)]\n")
27473
0
SLANG_RAW("    __init<U : __BuiltinArithmeticType>(CoopVec<U, N> other)\n")
27474
0
SLANG_RAW("    {\n")
27475
0
SLANG_RAW("        this.copyFrom(other);\n")
27476
0
SLANG_RAW("    }\n")
27477
0
SLANG_RAW("\n")
27478
0
SLANG_RAW("    [ForceInline]\n")
27479
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27480
0
SLANG_RAW("    __init<each U : __BuiltinArithmeticType>(expand each U args)\n")
27481
0
SLANG_RAW("    {\n")
27482
0
SLANG_RAW("        static_assert(countof(U) == N, \"number of arguments to CoopVec constructor must match number of elements\");\n")
27483
0
SLANG_RAW("        this = __makeCoopVec<T, N>(expand (__arithmetic_cast<T>(each args)));\n")
27484
0
SLANG_RAW("    }\n")
27485
0
SLANG_RAW("\n")
27486
0
SLANG_RAW("    [OverloadRank(-10)]\n")
27487
0
SLANG_RAW("    [ForceInline]\n")
27488
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27489
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27490
0
SLANG_RAW("    __init(int i)\n")
27491
0
SLANG_RAW("    {\n")
27492
0
SLANG_RAW("        this = CoopVec<T, N>(T(i));\n")
27493
0
SLANG_RAW("    }\n")
27494
0
SLANG_RAW("\n")
27495
0
SLANG_RAW("    [ForceInline]\n")
27496
0
SLANG_RAW("    __init(This x)\n")
27497
0
SLANG_RAW("    {\n")
27498
0
SLANG_RAW("        this = x;\n")
27499
0
SLANG_RAW("    }\n")
27500
0
SLANG_RAW("\n")
27501
0
SLANG_RAW("    //\n")
27502
0
SLANG_RAW("    // Simple setters\n")
27503
0
SLANG_RAW("    //\n")
27504
0
SLANG_RAW("\n")
27505
0
SLANG_RAW("    /// Copy values from another CoopVec instance into this one. The source CoopVec can have a different element type,\n")
27506
0
SLANG_RAW("    /// in which case appropriate type conversion will be performed.\n")
27507
0
SLANG_RAW("    /// @param other The source CoopVec to copy from.\n")
27508
0
SLANG_RAW("    [mutating]\n")
27509
0
SLANG_RAW("    [ForceInline]\n")
27510
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27511
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27512
0
SLANG_RAW("    [require(optix_coopvec)]\n")
27513
0
SLANG_RAW("    void copyFrom<U : __BuiltinArithmeticType>(CoopVec<U,N> other)\n")
27514
0
SLANG_RAW("    {\n")
27515
0
SLANG_RAW("        __target_switch\n")
27516
0
SLANG_RAW("        {\n")
27517
0
SLANG_RAW("        case hlsl:\n")
27518
0
SLANG_RAW("            __intrinsic_asm \"$0 = $1\";\n")
27519
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27520
0
SLANG_RAW("            __intrinsic_asm \".CopyFrom\";\n")
27521
0
SLANG_RAW("        case optix_coopvec:\n")
27522
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecCvt<$TR>(*($0));\";\n")
27523
0
SLANG_RAW("        default:\n")
27524
0
SLANG_RAW("            if (__isFloat<T>() && __isInt<U>())\n")
27525
0
SLANG_RAW("                this = __int_to_float_cast<T>(other);\n")
27526
0
SLANG_RAW("            else if (__isInt<T>() && __isFloat<U>())\n")
27527
0
SLANG_RAW("                this = __float_to_int_cast<T>(other);\n")
27528
0
SLANG_RAW("            else if (__isFloat<T>() && __isFloat<U>())\n")
27529
0
SLANG_RAW("                this = __real_cast<T>(other);\n")
27530
0
SLANG_RAW("            else if (__isInt<T>() && __isInt<U>())\n")
27531
0
SLANG_RAW("                this = __int_cast<T>(other);\n")
27532
0
SLANG_RAW("        }\n")
27533
0
SLANG_RAW("    }\n")
27534
0
SLANG_RAW("\n")
27535
0
SLANG_RAW("    /// Fill all elements of this CoopVec with the specified value.\n")
27536
0
SLANG_RAW("    /// @param t The value to fill all elements with.\n")
27537
0
SLANG_RAW("    [mutating]\n")
27538
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27539
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27540
0
SLANG_RAW("    void fill(T t)\n")
27541
0
SLANG_RAW("    {\n")
27542
0
SLANG_RAW("        __target_switch\n")
27543
0
SLANG_RAW("        {\n")
27544
0
SLANG_RAW("        case spirv:\n")
27545
0
SLANG_RAW("            this = spirv_asm {\n")
27546
0
SLANG_RAW("                OpExtension \"SPV_EXT_replicated_composites\";\n")
27547
0
SLANG_RAW("                OpCapability ReplicatedCompositesEXT;\n")
27548
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCompositeConstructReplicateEXT $t;\n")
27549
0
SLANG_RAW("            };\n")
27550
0
SLANG_RAW("        case hlsl:\n")
27551
0
SLANG_RAW("             __intrinsic_asm \"$0 = $1\";\n")
27552
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27553
0
SLANG_RAW("            __intrinsic_asm \".Fill\";\n")
27554
0
SLANG_RAW("        default:\n")
27555
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27556
0
SLANG_RAW("                this[i] = t;\n")
27557
0
SLANG_RAW("            return;\n")
27558
0
SLANG_RAW("        }\n")
27559
0
SLANG_RAW("    }\n")
27560
0
SLANG_RAW("\n")
27561
0
SLANG_RAW("    //\n")
27562
0
SLANG_RAW("    // Loading and storing\n")
27563
0
SLANG_RAW("    //\n")
27564
0
SLANG_RAW("\n")
27565
0
SLANG_RAW("    /// Store all elements of this CoopVec into a buffer at a specified offset.\n")
27566
0
SLANG_RAW("    /// Pointer accesses are 16-byte aligned.\n")
27567
0
SLANG_RAW("    /// @param buffer The destination buffer to store the values into.\n")
27568
0
SLANG_RAW("    /// @param byteOffset16ByteAligned The byte offset from the start of the buffer where the data will be stored. Must be 16-byte aligned.\n")
27569
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27570
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27571
0
SLANG_RAW("    void store(RWByteAddressBuffer buffer, int32_t byteOffset16ByteAligned = 0)\n")
27572
0
SLANG_RAW("    {\n")
27573
0
SLANG_RAW("        __target_switch\n")
27574
0
SLANG_RAW("        {\n")
27575
0
SLANG_RAW("        case spirv:\n")
27576
0
SLANG_RAW("            let ptr = buffer.GetBufferPointer();\n")
27577
0
SLANG_RAW("            spirv_asm\n")
27578
0
SLANG_RAW("            {\n")
27579
0
SLANG_RAW("                // TODO: Should this be a byte offset\n")
27580
0
SLANG_RAW("                OpCooperativeVectorStoreNV $ptr $byteOffset16ByteAligned $this None;\n")
27581
0
SLANG_RAW("            };\n")
27582
0
SLANG_RAW("        case hlsl:\n")
27583
0
SLANG_RAW("                __intrinsic_asm \"$1.Store< vector<$[0], $[1]> >($2, $0)\", T, N;\n")
27584
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27585
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27586
0
SLANG_RAW("                buffer.StoreByteOffset(byteOffset16ByteAligned + __elemToByteOffset<T>(i), this[i]);\n")
27587
0
SLANG_RAW("            return;\n")
27588
0
SLANG_RAW("        default:\n")
27589
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27590
0
SLANG_RAW("                buffer.StoreByteOffset(byteOffset16ByteAligned + __elemToByteOffset<T>(i), this[i]);\n")
27591
0
SLANG_RAW("            return;\n")
27592
0
SLANG_RAW("        }\n")
27593
0
SLANG_RAW("    }\n")
27594
0
SLANG_RAW("\n")
27595
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27596
0
SLANG_RAW("    void store(RWStructuredBuffer<T> buffer, int32_t byteOffset16ByteAligned = 0)\n")
27597
0
SLANG_RAW("    {\n")
27598
0
SLANG_RAW("        __target_switch\n")
27599
0
SLANG_RAW("        {\n")
27600
0
SLANG_RAW("        case spirv:\n")
27601
0
SLANG_RAW("            let ptr = __getStructuredBufferPtr(buffer);\n")
27602
0
SLANG_RAW("            spirv_asm\n")
27603
0
SLANG_RAW("            {\n")
27604
0
SLANG_RAW("                // TODO: Should this be a byte offset\n")
27605
0
SLANG_RAW("                OpCooperativeVectorStoreNV $ptr $byteOffset16ByteAligned $this None;\n")
27606
0
SLANG_RAW("            };\n")
27607
0
SLANG_RAW("        default:\n")
27608
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27609
0
SLANG_RAW("                buffer[i + __byteToElemOffset<T>(byteOffset16ByteAligned)] = this[i];\n")
27610
0
SLANG_RAW("        }\n")
27611
0
SLANG_RAW("    }\n")
27612
0
SLANG_RAW("\n")
27613
0
SLANG_RAW("    [ForceInline]\n")
27614
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27615
0
SLANG_RAW("    void store(T* buffer, int32_t byteOffset16ByteAligned = 0)\n")
27616
0
SLANG_RAW("    {\n")
27617
0
SLANG_RAW("        let pointer = Ptr<T[]>(buffer);\n")
27618
0
SLANG_RAW("        let alignment = 16;\n")
27619
0
SLANG_RAW("        return spirv_asm\n")
27620
0
SLANG_RAW("        {\n")
27621
0
SLANG_RAW("            OpCooperativeVectorStoreNV $pointer $byteOffset16ByteAligned $this Aligned !alignment;\n")
27622
0
SLANG_RAW("        };\n")
27623
0
SLANG_RAW("    }\n")
27624
0
SLANG_RAW("\n")
27625
0
SLANG_RAW("    // TODO: make this function an intrinsic and support all types via the single intrinsic\n")
27626
0
SLANG_RAW("    [require(cooperative_vector, vk_mem_model)]\n")
27627
0
SLANG_RAW("    void storeCoherent(T* buffer, int32_t byteOffset16ByteAligned = 0, constexpr MemoryScope memoryScope = MemoryScope::Device)\n")
27628
0
SLANG_RAW("    {\n")
27629
0
SLANG_RAW("        enableVMMDeviceScopeCapabilityIfNeeded(memoryScope);\n")
27630
0
SLANG_RAW("        let pointer = Ptr<T[]>(buffer);\n")
27631
0
SLANG_RAW("        let alignment = 16U;\n")
27632
0
SLANG_RAW("        const int32_t scope = (int32_t)memoryScope;\n")
27633
0
SLANG_RAW("        spirv_asm\n")
27634
0
SLANG_RAW("        {\n")
27635
0
SLANG_RAW("            OpCooperativeVectorStoreNV $pointer $byteOffset16ByteAligned $this Aligned|MakePointerAvailable|NonPrivatePointer !alignment $scope;\n")
27636
0
SLANG_RAW("        };\n")
27637
0
SLANG_RAW("    }\n")
27638
0
SLANG_RAW("\n")
27639
0
SLANG_RAW("    [ForceInline]\n")
27640
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27641
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27642
0
SLANG_RAW("    void store<let M : int>(__ref groupshared T[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27643
0
SLANG_RAW("    {\n")
27644
0
SLANG_RAW("        static_assert(N <= M, \"The destination vector size is smaller than the input.\");\n")
27645
0
SLANG_RAW("        __target_switch\n")
27646
0
SLANG_RAW("        {\n")
27647
0
SLANG_RAW("        case spirv:\n")
27648
0
SLANG_RAW("            spirv_asm{\n")
27649
0
SLANG_RAW("                OpCooperativeVectorStoreNV &data $byteOffset16ByteAligned $this None;\n")
27650
0
SLANG_RAW("            };\n")
27651
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27652
0
SLANG_RAW("            this.__Store(data, __byteToElemOffset<T>(byteOffset16ByteAligned));\n")
27653
0
SLANG_RAW("            return;\n")
27654
0
SLANG_RAW("        default:\n")
27655
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27656
0
SLANG_RAW("                data[i + __byteToElemOffset<T>(byteOffset16ByteAligned)] = this[i];\n")
27657
0
SLANG_RAW("            return;\n")
27658
0
SLANG_RAW("        }\n")
27659
0
SLANG_RAW("    }\n")
27660
0
SLANG_RAW("\n")
27661
0
SLANG_RAW("    /// Store the value to a groupshared array of any type. This method is only available when targeting SPIR-V.\n")
27662
0
SLANG_RAW("    /// @param data The destination array where the data will be stored. The array element type can be different from the CoopVec element type.\n")
27663
0
SLANG_RAW("    /// @param byteOffset16ByteAligned The byte offset from the start of `data`. Must be a multiple of 16 bytes.\n")
27664
0
SLANG_RAW("    [ForceInline]\n")
27665
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27666
0
SLANG_RAW("    void storeAny<U, let M : int>(__ref groupshared U[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27667
0
SLANG_RAW("    {\n")
27668
0
SLANG_RAW("        static_assert(N <= M, \"The destination vector size is smaller than the input.\");\n")
27669
0
SLANG_RAW("        __target_switch\n")
27670
0
SLANG_RAW("        {\n")
27671
0
SLANG_RAW("        case spirv:\n")
27672
0
SLANG_RAW("            spirv_asm{\n")
27673
0
SLANG_RAW("                OpCooperativeVectorStoreNV &data $byteOffset16ByteAligned $this None;\n")
27674
0
SLANG_RAW("            };\n")
27675
0
SLANG_RAW("        }\n")
27676
0
SLANG_RAW("    }\n")
27677
0
SLANG_RAW("\n")
27678
0
SLANG_RAW("    [ForceInline]\n")
27679
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27680
0
SLANG_RAW("    void storeAny<U, let M : int, let L : int>(__ref groupshared vector<U, L>[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27681
0
SLANG_RAW("    {\n")
27682
0
SLANG_RAW("        __target_switch\n")
27683
0
SLANG_RAW("        {\n")
27684
0
SLANG_RAW("        case spirv:\n")
27685
0
SLANG_RAW("            spirv_asm{\n")
27686
0
SLANG_RAW("                OpCooperativeVectorStoreNV &data $byteOffset16ByteAligned $this None;\n")
27687
0
SLANG_RAW("            };\n")
27688
0
SLANG_RAW("        }\n")
27689
0
SLANG_RAW("    }\n")
27690
0
SLANG_RAW("\n")
27691
0
SLANG_RAW("    /// Load values from a byte-addressable buffer into a cooperative vector.\n")
27692
0
SLANG_RAW("    /// Pointer accesses are 16-byte aligned.\n")
27693
0
SLANG_RAW("    /// @param buffer The source buffer to load data from.\n")
27694
0
SLANG_RAW("    /// @param byteOffset16ByteAligned The byte offset from the start of the buffer. Must be 16-byte aligned.\n")
27695
0
SLANG_RAW("    /// @return A new cooperative vector containing the loaded values.\n")
27696
0
SLANG_RAW("    [__NoSideEffect]\n")
27697
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27698
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27699
0
SLANG_RAW("    [require(optix_coopvec)]\n")
27700
0
SLANG_RAW("    static CoopVec<T, N> load(ByteAddressBuffer buffer, int32_t byteOffset16ByteAligned = 0)\n")
27701
0
SLANG_RAW("    {\n")
27702
0
SLANG_RAW("        __target_switch\n")
27703
0
SLANG_RAW("        {\n")
27704
0
SLANG_RAW("        case spirv:\n")
27705
0
SLANG_RAW("            let ptr = buffer.GetBufferPointer();\n")
27706
0
SLANG_RAW("            return spirv_asm\n")
27707
0
SLANG_RAW("            {\n")
27708
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $ptr $byteOffset16ByteAligned None;\n")
27709
0
SLANG_RAW("            };\n")
27710
0
SLANG_RAW("        case hlsl:\n")
27711
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27712
0
SLANG_RAW("            CoopVec<T, N> ret;\n")
27713
0
SLANG_RAW("            ret.__Load(buffer, byteOffset16ByteAligned);\n")
27714
0
SLANG_RAW("            return ret;\n")
27715
0
SLANG_RAW("        case optix_coopvec:\n")
27716
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecLoad<$TR>((CUdeviceptr)(&($0)));\";\n")
27717
0
SLANG_RAW("        default:\n")
27718
0
SLANG_RAW("            var vec = CoopVec<T, N>();\n")
27719
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27720
0
SLANG_RAW("                vec[i] = buffer.LoadByteOffset<T>(byteOffset16ByteAligned + __elemToByteOffset<T>(i));\n")
27721
0
SLANG_RAW("            return vec;\n")
27722
0
SLANG_RAW("        }\n")
27723
0
SLANG_RAW("        return CoopVec<T, N>();\n")
27724
0
SLANG_RAW("    }\n")
27725
0
SLANG_RAW("\n")
27726
0
SLANG_RAW("    [__NoSideEffect]\n")
27727
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27728
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27729
0
SLANG_RAW("    [require(optix_coopvec)]\n")
27730
0
SLANG_RAW("    static CoopVec<T, N> load(RWByteAddressBuffer buffer, int32_t byteOffset16ByteAligned = 0)\n")
27731
0
SLANG_RAW("    {\n")
27732
0
SLANG_RAW("        __target_switch\n")
27733
0
SLANG_RAW("        {\n")
27734
0
SLANG_RAW("        case spirv:\n")
27735
0
SLANG_RAW("            let ptr = buffer.GetBufferPointer();\n")
27736
0
SLANG_RAW("            return spirv_asm\n")
27737
0
SLANG_RAW("            {\n")
27738
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $ptr $byteOffset16ByteAligned None;\n")
27739
0
SLANG_RAW("            };\n")
27740
0
SLANG_RAW("        case hlsl:\n")
27741
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27742
0
SLANG_RAW("            CoopVec<T, N> ret;\n")
27743
0
SLANG_RAW("            ret.__Load(buffer, byteOffset16ByteAligned);\n")
27744
0
SLANG_RAW("            return ret;\n")
27745
0
SLANG_RAW("        case optix_coopvec:\n")
27746
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecLoad<$TR>((CUdeviceptr)(&($0)));\";\n")
27747
0
SLANG_RAW("        default:\n")
27748
0
SLANG_RAW("            var vec = CoopVec<T, N>();\n")
27749
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27750
0
SLANG_RAW("                vec[i] = buffer.LoadByteOffset<T>(byteOffset16ByteAligned + __elemToByteOffset<T>(i));\n")
27751
0
SLANG_RAW("            return vec;\n")
27752
0
SLANG_RAW("        }\n")
27753
0
SLANG_RAW("        return CoopVec<T, N>();\n")
27754
0
SLANG_RAW("    }\n")
27755
0
SLANG_RAW("\n")
27756
0
SLANG_RAW("    [__NoSideEffect]\n")
27757
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27758
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27759
0
SLANG_RAW("    static CoopVec<T, N> load(StructuredBuffer<T> buffer, int32_t byteOffset16ByteAligned = 0)\n")
27760
0
SLANG_RAW("    {\n")
27761
0
SLANG_RAW("        __target_switch\n")
27762
0
SLANG_RAW("        {\n")
27763
0
SLANG_RAW("        case spirv:\n")
27764
0
SLANG_RAW("            let ptr = __getStructuredBufferPtr(buffer);\n")
27765
0
SLANG_RAW("            return spirv_asm\n")
27766
0
SLANG_RAW("            {\n")
27767
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $ptr $byteOffset16ByteAligned None;\n")
27768
0
SLANG_RAW("            };\n")
27769
0
SLANG_RAW("        default:\n")
27770
0
SLANG_RAW("            var vec = CoopVec<T, N>();\n")
27771
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27772
0
SLANG_RAW("                vec[i] = buffer[__byteToElemOffset<T>(byteOffset16ByteAligned) + i];\n")
27773
0
SLANG_RAW("            return vec;\n")
27774
0
SLANG_RAW("        }\n")
27775
0
SLANG_RAW("        return CoopVec<T, N>();\n")
27776
0
SLANG_RAW("    }\n")
27777
0
SLANG_RAW("\n")
27778
0
SLANG_RAW("    [__NoSideEffect]\n")
27779
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27780
0
SLANG_RAW("    static CoopVec<T, N> load(RWStructuredBuffer<T> buffer, int32_t byteOffset16ByteAligned = 0)\n")
27781
0
SLANG_RAW("    {\n")
27782
0
SLANG_RAW("        __target_switch\n")
27783
0
SLANG_RAW("        {\n")
27784
0
SLANG_RAW("        case spirv:\n")
27785
0
SLANG_RAW("            let ptr = __getStructuredBufferPtr(buffer);\n")
27786
0
SLANG_RAW("            return spirv_asm\n")
27787
0
SLANG_RAW("            {\n")
27788
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $ptr $byteOffset16ByteAligned None;\n")
27789
0
SLANG_RAW("            };\n")
27790
0
SLANG_RAW("        default:\n")
27791
0
SLANG_RAW("            var vec = CoopVec<T, N>();\n")
27792
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27793
0
SLANG_RAW("                vec[i] = buffer[__byteToElemOffset<T>(byteOffset16ByteAligned) + i];\n")
27794
0
SLANG_RAW("            return vec;\n")
27795
0
SLANG_RAW("        }\n")
27796
0
SLANG_RAW("    }\n")
27797
0
SLANG_RAW("\n")
27798
0
SLANG_RAW("    [ForceInline]\n")
27799
0
SLANG_RAW("    [__NoSideEffect]\n")
27800
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27801
0
SLANG_RAW("    static CoopVec<T, N> load(T* buffer, int32_t byteOffset16ByteAligned = 0)\n")
27802
0
SLANG_RAW("    {\n")
27803
0
SLANG_RAW("        let pointer = Ptr<T[]>(buffer);\n")
27804
0
SLANG_RAW("        let alignment = 16;\n")
27805
0
SLANG_RAW("        return spirv_asm\n")
27806
0
SLANG_RAW("        {\n")
27807
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $pointer $byteOffset16ByteAligned Aligned !alignment;\n")
27808
0
SLANG_RAW("        };\n")
27809
0
SLANG_RAW("    }\n")
27810
0
SLANG_RAW("\n")
27811
0
SLANG_RAW("    // TODO: make this function an intrinsic and support all types via the single intrinsic\n")
27812
0
SLANG_RAW("    [require(cooperative_vector, vk_mem_model)]\n")
27813
0
SLANG_RAW("    static CoopVec<T, N> loadCoherent(T* buffer, int32_t byteOffset16ByteAligned = 0, constexpr MemoryScope memoryScope = MemoryScope::Device)\n")
27814
0
SLANG_RAW("    {\n")
27815
0
SLANG_RAW("        enableVMMDeviceScopeCapabilityIfNeeded(memoryScope);\n")
27816
0
SLANG_RAW("        let pointer = Ptr<T[]>(buffer);\n")
27817
0
SLANG_RAW("        let alignment = 16U;\n")
27818
0
SLANG_RAW("        const int32_t scope = (int32_t)memoryScope;\n")
27819
0
SLANG_RAW("        return spirv_asm\n")
27820
0
SLANG_RAW("        {\n")
27821
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV $pointer $byteOffset16ByteAligned Aligned|MakePointerVisible|NonPrivatePointer !alignment $scope;\n")
27822
0
SLANG_RAW("        };\n")
27823
0
SLANG_RAW("    }\n")
27824
0
SLANG_RAW("\n")
27825
0
SLANG_RAW("    // Groupshared\n")
27826
0
SLANG_RAW("    [ForceInline]\n")
27827
0
SLANG_RAW("    [__NoSideEffect]\n")
27828
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27829
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27830
0
SLANG_RAW("    [require(optix_coopvec)]\n")
27831
0
SLANG_RAW("    static CoopVec<T, N> load<let M : int>(__constref groupshared const T[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27832
0
SLANG_RAW("    {\n")
27833
0
SLANG_RAW("        static_assert(N <= M, \"The destination vector size is smaller than the input.\");\n")
27834
0
SLANG_RAW("        __target_switch\n")
27835
0
SLANG_RAW("        {\n")
27836
0
SLANG_RAW("        case spirv:\n")
27837
0
SLANG_RAW("            return spirv_asm{\n")
27838
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV &data $byteOffset16ByteAligned None\n")
27839
0
SLANG_RAW("            };\n")
27840
0
SLANG_RAW("        case hlsl:\n")
27841
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
27842
0
SLANG_RAW("            CoopVec<T, N> ret;\n")
27843
0
SLANG_RAW("            ret.__Load(data, __byteToElemOffset<T>(byteOffset16ByteAligned));\n")
27844
0
SLANG_RAW("            return ret;\n")
27845
0
SLANG_RAW("        case optix_coopvec:\n")
27846
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecLoad<$TR>((CUdeviceptr)(&($0)));\";\n")
27847
0
SLANG_RAW("        default:\n")
27848
0
SLANG_RAW("            CoopVec<T,N> result;\n")
27849
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
27850
0
SLANG_RAW("                result[i] = data[i + __byteToElemOffset<T>(byteOffset16ByteAligned)];\n")
27851
0
SLANG_RAW("            return result;\n")
27852
0
SLANG_RAW("        }\n")
27853
0
SLANG_RAW("    }\n")
27854
0
SLANG_RAW("\n")
27855
0
SLANG_RAW("    /// Load values from a groupshared array into a CoopVec, allowing type conversion between source and destination elements.\n")
27856
0
SLANG_RAW("    /// This operation is only available when targeting SPIR-V.\n")
27857
0
SLANG_RAW("    /// @param data The source groupshared array to load from. The element type U can be different from the CoopVec element type T.\n")
27858
0
SLANG_RAW("    /// @param byteOffset16ByteAligned The byte offset from the start of the array. Must be 16-byte aligned.\n")
27859
0
SLANG_RAW("    /// @return A new CoopVec containing the loaded and type-converted values.\n")
27860
0
SLANG_RAW("    [ForceInline]\n")
27861
0
SLANG_RAW("    [__NoSideEffect]\n")
27862
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27863
0
SLANG_RAW("    static CoopVec<T, N> loadAny<U : __BuiltinArithmeticType, let M : int>(__constref groupshared const U[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27864
0
SLANG_RAW("    {\n")
27865
0
SLANG_RAW("        static_assert(N <= M, \"The destination vector size is smaller than the input.\");\n")
27866
0
SLANG_RAW("        __target_switch\n")
27867
0
SLANG_RAW("        {\n")
27868
0
SLANG_RAW("        case spirv:\n")
27869
0
SLANG_RAW("            return spirv_asm{\n")
27870
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV &data $byteOffset16ByteAligned None\n")
27871
0
SLANG_RAW("            };\n")
27872
0
SLANG_RAW("        }\n")
27873
0
SLANG_RAW("    }\n")
27874
0
SLANG_RAW("\n")
27875
0
SLANG_RAW("    [ForceInline]\n")
27876
0
SLANG_RAW("    [__NoSideEffect]\n")
27877
0
SLANG_RAW("    [require(spirv, cooperative_vector)]\n")
27878
0
SLANG_RAW("    static CoopVec<T, N> loadAny<U : __BuiltinArithmeticType, let M : int, let L : int>(__constref groupshared const vector<U, L>[M] data, int32_t byteOffset16ByteAligned = 0)\n")
27879
0
SLANG_RAW("    {\n")
27880
0
SLANG_RAW("        __target_switch\n")
27881
0
SLANG_RAW("        {\n")
27882
0
SLANG_RAW("        case spirv:\n")
27883
0
SLANG_RAW("            return spirv_asm{\n")
27884
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpCooperativeVectorLoadNV &data $byteOffset16ByteAligned None\n")
27885
0
SLANG_RAW("            };\n")
27886
0
SLANG_RAW("        }\n")
27887
0
SLANG_RAW("    }\n")
27888
0
SLANG_RAW("\n")
27889
0
SLANG_RAW("    //\n")
27890
0
SLANG_RAW("    // Subscript\n")
27891
0
SLANG_RAW("    //\n")
27892
0
SLANG_RAW("\n")
27893
0
SLANG_RAW("    __intrinsic_op(")
27894
0
SLANG_SPLICE(kIROp_GetElement
27895
0
)
27896
0
SLANG_RAW(")\n")
27897
0
SLANG_RAW("    [__NoSideEffect]\n")
27898
0
SLANG_RAW("    T __indexRead(int index);\n")
27899
0
SLANG_RAW("\n")
27900
0
SLANG_RAW("    __intrinsic_op(")
27901
0
SLANG_SPLICE(kIROp_GetElementPtr
27902
0
)
27903
0
SLANG_RAW(")\n")
27904
0
SLANG_RAW("    [__ref]\n")
27905
0
SLANG_RAW("    [__NoSideEffect]\n")
27906
0
SLANG_RAW("    Ref<T> __indexRef(int index);\n")
27907
0
SLANG_RAW("\n")
27908
0
SLANG_RAW("    [ForceInline]\n")
27909
0
SLANG_RAW("    [__NoSideEffect]\n")
27910
0
SLANG_RAW("    int getCount()\n")
27911
0
SLANG_RAW("    {\n")
27912
0
SLANG_RAW("        return N;\n")
27913
0
SLANG_RAW("    }\n")
27914
0
SLANG_RAW("\n")
27915
0
SLANG_RAW("    /// Access an individual element in the Cooperative vector by index.\n")
27916
0
SLANG_RAW("    __subscript(int index) -> T\n")
27917
0
SLANG_RAW("    {\n")
27918
0
SLANG_RAW("        [ForceInline]\n")
27919
0
SLANG_RAW("        [__NoSideEffect]\n")
27920
0
SLANG_RAW("        [nonmutating]\n")
27921
0
SLANG_RAW("        [require(cooperative_vector)]\n")
27922
0
SLANG_RAW("        [require(hlsl_coopvec_poc)]\n")
27923
0
SLANG_RAW("        get\n")
27924
0
SLANG_RAW("        {\n")
27925
0
SLANG_RAW("            __target_switch\n")
27926
0
SLANG_RAW("            {\n")
27927
0
SLANG_RAW("            case hlsl_coopvec_poc:\n")
27928
0
SLANG_RAW("                __intrinsic_asm \".ReadFromIndex\";\n")
27929
0
SLANG_RAW("            default: return __indexRead(index);\n")
27930
0
SLANG_RAW("            }\n")
27931
0
SLANG_RAW("        }\n")
27932
0
SLANG_RAW("\n")
27933
0
SLANG_RAW("        [ForceInline]\n")
27934
0
SLANG_RAW("        [mutating]\n")
27935
0
SLANG_RAW("        [require(cooperative_vector)]\n")
27936
0
SLANG_RAW("        [require(hlsl_coopvec_poc)]\n")
27937
0
SLANG_RAW("        set\n")
27938
0
SLANG_RAW("        {\n")
27939
0
SLANG_RAW("            __target_switch\n")
27940
0
SLANG_RAW("            {\n")
27941
0
SLANG_RAW("            case hlsl_coopvec_poc:\n")
27942
0
SLANG_RAW("                __intrinsic_asm \".WriteToIndex\";\n")
27943
0
SLANG_RAW("            default: __indexRef(index) = newValue;\n")
27944
0
SLANG_RAW("            }\n")
27945
0
SLANG_RAW("        }\n")
27946
0
SLANG_RAW("\n")
27947
0
SLANG_RAW("        // Unavailable on HLSL\n")
27948
0
SLANG_RAW("        // The CoopVector HLSL spec says that indexing with a subscript\n")
27949
0
SLANG_RAW("        // operation can work, but dxc currently crashes with this\n")
27950
0
SLANG_RAW("        // __intrinsic_op(")
27951
0
SLANG_SPLICE(kIROp_GetElementPtr
27952
0
)
27953
0
SLANG_RAW(")\n")
27954
0
SLANG_RAW("        // [__ref]\n")
27955
0
SLANG_RAW("        // ref;\n")
27956
0
SLANG_RAW("    }\n")
27957
0
SLANG_RAW("\n")
27958
0
SLANG_RAW("    /// Creates a new cooperative vector with all elements initialized to the specified scalar value.\n")
27959
0
SLANG_RAW("    /// @param t The scalar value to replicate across all elements.\n")
27960
0
SLANG_RAW("    /// @return A new cooperative vector where each element equals the input value.\n")
27961
0
SLANG_RAW("    [require(cooperative_vector)]\n")
27962
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
27963
0
SLANG_RAW("    static CoopVec<T, N> replicate(T t)\n")
27964
0
SLANG_RAW("    {\n")
27965
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
27966
0
SLANG_RAW("        ret.fill(t);\n")
27967
0
SLANG_RAW("        return ret;\n")
27968
0
SLANG_RAW("    }\n")
27969
0
SLANG_RAW("\n")
27970
0
SLANG_RAW("    //\n")
27971
0
SLANG_RAW("    // IComparable\n")
27972
0
SLANG_RAW("    //\n")
27973
0
SLANG_RAW("\n")
27974
0
SLANG_RAW("    /// Checks if this cooperative vector is equal to another cooperative vector by comparing all elements.\n")
27975
0
SLANG_RAW("    /// @param other The cooperative vector to compare against.\n")
27976
0
SLANG_RAW("    /// @return True if all corresponding elements are equal, false otherwise.\n")
27977
0
SLANG_RAW("    bool equals(This other)\n")
27978
0
SLANG_RAW("    {\n")
27979
0
SLANG_RAW("        for (int i = 0; i < N; i++)\n")
27980
0
SLANG_RAW("        {\n")
27981
0
SLANG_RAW("            if (this[i] != other[i])\n")
27982
0
SLANG_RAW("            {\n")
27983
0
SLANG_RAW("                return false;\n")
27984
0
SLANG_RAW("            }\n")
27985
0
SLANG_RAW("        }\n")
27986
0
SLANG_RAW("        return true;\n")
27987
0
SLANG_RAW("    }\n")
27988
0
SLANG_RAW("\n")
27989
0
SLANG_RAW("    /// Compares two cooperative vectors lexicographically.\n")
27990
0
SLANG_RAW("    /// @param other The cooperative vector to compare against.\n")
27991
0
SLANG_RAW("    /// @return True if this vector is lexicographically less than the other vector.\n")
27992
0
SLANG_RAW("    /// @remarks This function exists only to conform to IComparable. For cooperative vectors,\n")
27993
0
SLANG_RAW("    /// lexicographical comparison has limited practical use since the vectors are meant for\n")
27994
0
SLANG_RAW("    /// parallel computation rather than ordering.\n")
27995
0
SLANG_RAW("    bool lessThan(This other)\n")
27996
0
SLANG_RAW("    {\n")
27997
0
SLANG_RAW("        for (int i = 0; i < N; i++)\n")
27998
0
SLANG_RAW("        {\n")
27999
0
SLANG_RAW("            if (this[i] < other[i])\n")
28000
0
SLANG_RAW("            {\n")
28001
0
SLANG_RAW("                return true;\n")
28002
0
SLANG_RAW("            }\n")
28003
0
SLANG_RAW("            else if (this[i] > other[i])\n")
28004
0
SLANG_RAW("            {\n")
28005
0
SLANG_RAW("                return false;\n")
28006
0
SLANG_RAW("            }\n")
28007
0
SLANG_RAW("        }\n")
28008
0
SLANG_RAW("        return false;\n")
28009
0
SLANG_RAW("    }\n")
28010
0
SLANG_RAW("\n")
28011
0
SLANG_RAW("    /// Compares two cooperative vectors lexicographically.\n")
28012
0
SLANG_RAW("    /// @param other The cooperative vector to compare against.\n")
28013
0
SLANG_RAW("    /// @return True if this vector is lexicographically less than or equal to the other vector.\n")
28014
0
SLANG_RAW("    /// @remarks This function exists only to conform to IComparable. For cooperative vectors,\n")
28015
0
SLANG_RAW("    /// lexicographical comparison has limited practical use since the vectors are meant for\n")
28016
0
SLANG_RAW("    /// parallel computation rather than ordering.\n")
28017
0
SLANG_RAW("    bool lessThanOrEquals(This other)\n")
28018
0
SLANG_RAW("    {\n")
28019
0
SLANG_RAW("        for (int i = 0; i < N; i++)\n")
28020
0
SLANG_RAW("        {\n")
28021
0
SLANG_RAW("            if (this[i] < other[i])\n")
28022
0
SLANG_RAW("            {\n")
28023
0
SLANG_RAW("                return true;\n")
28024
0
SLANG_RAW("            }\n")
28025
0
SLANG_RAW("            else if (this[i] > other[i])\n")
28026
0
SLANG_RAW("            {\n")
28027
0
SLANG_RAW("                return false;\n")
28028
0
SLANG_RAW("            }\n")
28029
0
SLANG_RAW("        }\n")
28030
0
SLANG_RAW("        return true;\n")
28031
0
SLANG_RAW("    }\n")
28032
0
SLANG_RAW("\n")
28033
0
SLANG_RAW("    //\n")
28034
0
SLANG_RAW("    // Arithmetic\n")
28035
0
SLANG_RAW("    //\n")
28036
0
SLANG_RAW("\n")
28037
0
SLANG_RAW("    __intrinsic_op(")
28038
0
SLANG_SPLICE(kIROp_Add
28039
0
)
28040
0
SLANG_RAW(")\n")
28041
0
SLANG_RAW("    This __pureAdd(This other);\n")
28042
0
SLANG_RAW("\n")
28043
0
SLANG_RAW("    [mutating]\n")
28044
0
SLANG_RAW("    [ForceInline]\n")
28045
0
SLANG_RAW("    [require(hlsl)]\n")
28046
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28047
0
SLANG_RAW("    void __mutAdd(This other)\n")
28048
0
SLANG_RAW("    {\n")
28049
0
SLANG_RAW("        __target_switch\n")
28050
0
SLANG_RAW("        {\n")
28051
0
SLANG_RAW("        case hlsl:\n")
28052
0
SLANG_RAW("            __intrinsic_asm \"$0 += $1\";\n")
28053
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28054
0
SLANG_RAW("            __intrinsic_asm \".Add\";\n")
28055
0
SLANG_RAW("        }\n")
28056
0
SLANG_RAW("    }\n")
28057
0
SLANG_RAW("\n")
28058
0
SLANG_RAW("    /// Performs component-wise addition with another cooperative vector.\n")
28059
0
SLANG_RAW("    /// @param other The cooperative vector to add to this vector.\n")
28060
0
SLANG_RAW("    /// @return A new cooperative vector containing the sum of the two vectors.\n")
28061
0
SLANG_RAW("    // TODO: Why is this ForceInline necessary for hlsl, dxc bug?\n")
28062
0
SLANG_RAW("    [ForceInline]\n")
28063
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28064
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28065
0
SLANG_RAW("    [require(optix_coopvec)]\n")
28066
0
SLANG_RAW("    This add(This other)\n")
28067
0
SLANG_RAW("    {\n")
28068
0
SLANG_RAW("        __target_switch\n")
28069
0
SLANG_RAW("        {\n")
28070
0
SLANG_RAW("        case hlsl:\n")
28071
0
SLANG_RAW("            __intrinsic_asm \"$0 + $1\";\n")
28072
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28073
0
SLANG_RAW("            This ret = this;\n")
28074
0
SLANG_RAW("            ret.__mutAdd(other);\n")
28075
0
SLANG_RAW("            return ret;\n")
28076
0
SLANG_RAW("        case optix_coopvec:\n")
28077
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecAdd($0, $1)\";\n")
28078
0
SLANG_RAW("        default: return __pureAdd(other);\n")
28079
0
SLANG_RAW("        }\n")
28080
0
SLANG_RAW("    }\n")
28081
0
SLANG_RAW("\n")
28082
0
SLANG_RAW("    __intrinsic_op(")
28083
0
SLANG_SPLICE(kIROp_Sub
28084
0
)
28085
0
SLANG_RAW(")\n")
28086
0
SLANG_RAW("    This __pureSub(This other);\n")
28087
0
SLANG_RAW("\n")
28088
0
SLANG_RAW("    [mutating]\n")
28089
0
SLANG_RAW("    [require(hlsl)]\n")
28090
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28091
0
SLANG_RAW("    void __mutSub(This other)\n")
28092
0
SLANG_RAW("    {\n")
28093
0
SLANG_RAW("        __target_switch\n")
28094
0
SLANG_RAW("        {\n")
28095
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0 -= $1\";\n")
28096
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Subtract\";\n")
28097
0
SLANG_RAW("        }\n")
28098
0
SLANG_RAW("    }\n")
28099
0
SLANG_RAW("\n")
28100
0
SLANG_RAW("    /// Performs component-wise subtraction with another cooperative vector.\n")
28101
0
SLANG_RAW("    /// @param other The cooperative vector to subtract from this vector.\n")
28102
0
SLANG_RAW("    /// @return A new cooperative vector containing the difference of the two vectors.\n")
28103
0
SLANG_RAW("    [ForceInline]\n")
28104
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28105
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28106
0
SLANG_RAW("    [require(optix_coopvec)]\n")
28107
0
SLANG_RAW("    This sub(This other)\n")
28108
0
SLANG_RAW("    {\n")
28109
0
SLANG_RAW("        __target_switch\n")
28110
0
SLANG_RAW("        {\n")
28111
0
SLANG_RAW("        case hlsl:\n")
28112
0
SLANG_RAW("            __intrinsic_asm \"$0 - $1\";\n")
28113
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28114
0
SLANG_RAW("            This ret = this;\n")
28115
0
SLANG_RAW("            ret.__mutSub(other);\n")
28116
0
SLANG_RAW("            return ret;\n")
28117
0
SLANG_RAW("        case optix_coopvec:\n")
28118
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecSub($0, $1)\";\n")
28119
0
SLANG_RAW("        default: return __pureSub(other);\n")
28120
0
SLANG_RAW("        }\n")
28121
0
SLANG_RAW("    }\n")
28122
0
SLANG_RAW("\n")
28123
0
SLANG_RAW("    __intrinsic_op(")
28124
0
SLANG_SPLICE(kIROp_Mul
28125
0
)
28126
0
SLANG_RAW(")\n")
28127
0
SLANG_RAW("    This __pureMul(This other);\n")
28128
0
SLANG_RAW("\n")
28129
0
SLANG_RAW("    [mutating]\n")
28130
0
SLANG_RAW("    [require(hlsl)]\n")
28131
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28132
0
SLANG_RAW("    void __mutMul(This other)\n")
28133
0
SLANG_RAW("    {\n")
28134
0
SLANG_RAW("        __target_switch\n")
28135
0
SLANG_RAW("        {\n")
28136
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0 *= $1\";\n")
28137
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Multiply\";\n")
28138
0
SLANG_RAW("        }\n")
28139
0
SLANG_RAW("    }\n")
28140
0
SLANG_RAW("\n")
28141
0
SLANG_RAW("    /// Performs component-wise multiplication with another cooperative vector.\n")
28142
0
SLANG_RAW("    /// @param other The cooperative vector to multiply with this vector.\n")
28143
0
SLANG_RAW("    /// @return A new cooperative vector containing the product of the two vectors.\n")
28144
0
SLANG_RAW("    [ForceInline]\n")
28145
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28146
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28147
0
SLANG_RAW("    [require(optix_coopvec)]\n")
28148
0
SLANG_RAW("    This mul(This other)\n")
28149
0
SLANG_RAW("    {\n")
28150
0
SLANG_RAW("        __target_switch\n")
28151
0
SLANG_RAW("        {\n")
28152
0
SLANG_RAW("        case hlsl:\n")
28153
0
SLANG_RAW("            __intrinsic_asm \"$0 * $1\";\n")
28154
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28155
0
SLANG_RAW("            This ret = this;\n")
28156
0
SLANG_RAW("            ret.__mutMul(other);\n")
28157
0
SLANG_RAW("            return ret;\n")
28158
0
SLANG_RAW("        case optix_coopvec:\n")
28159
0
SLANG_RAW("            __intrinsic_asm \"optixCoopVecMul($0, $1)\";\n")
28160
0
SLANG_RAW("        default: return __pureMul(other);\n")
28161
0
SLANG_RAW("        }\n")
28162
0
SLANG_RAW("    }\n")
28163
0
SLANG_RAW("\n")
28164
0
SLANG_RAW("    __intrinsic_op(")
28165
0
SLANG_SPLICE(kIROp_Div
28166
0
)
28167
0
SLANG_RAW(")\n")
28168
0
SLANG_RAW("    This __pureDiv(This other);\n")
28169
0
SLANG_RAW("\n")
28170
0
SLANG_RAW("    [mutating]\n")
28171
0
SLANG_RAW("    [require(hlsl)]\n")
28172
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28173
0
SLANG_RAW("    void __mutDiv(This other)\n")
28174
0
SLANG_RAW("    {\n")
28175
0
SLANG_RAW("        __target_switch\n")
28176
0
SLANG_RAW("        {\n")
28177
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0 /= $1\";\n")
28178
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Divide\";\n")
28179
0
SLANG_RAW("        }\n")
28180
0
SLANG_RAW("    }\n")
28181
0
SLANG_RAW("\n")
28182
0
SLANG_RAW("    /// Performs component-wise division with another cooperative vector.\n")
28183
0
SLANG_RAW("    /// @param other The cooperative vector to divide this vector by.\n")
28184
0
SLANG_RAW("    /// @return A new cooperative vector containing the quotient of the two vectors.\n")
28185
0
SLANG_RAW("    [ForceInline]\n")
28186
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28187
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28188
0
SLANG_RAW("    This div(This other)\n")
28189
0
SLANG_RAW("    {\n")
28190
0
SLANG_RAW("        __target_switch\n")
28191
0
SLANG_RAW("        {\n")
28192
0
SLANG_RAW("        case hlsl:\n")
28193
0
SLANG_RAW("            __intrinsic_asm \"$0 / $1\";\n")
28194
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28195
0
SLANG_RAW("            This ret = this;\n")
28196
0
SLANG_RAW("            ret.__mutDiv(other);\n")
28197
0
SLANG_RAW("            return ret;\n")
28198
0
SLANG_RAW("        default: return __pureDiv(other);\n")
28199
0
SLANG_RAW("        }\n")
28200
0
SLANG_RAW("    }\n")
28201
0
SLANG_RAW("\n")
28202
0
SLANG_RAW("    [mutating]\n")
28203
0
SLANG_RAW("    [require(hlsl)]\n")
28204
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28205
0
SLANG_RAW("    void __mutMod(This other)\n")
28206
0
SLANG_RAW("    {\n")
28207
0
SLANG_RAW("        __target_switch\n")
28208
0
SLANG_RAW("        {\n")
28209
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0 %= %1\";\n")
28210
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Mod\";\n")
28211
0
SLANG_RAW("        }\n")
28212
0
SLANG_RAW("    }\n")
28213
0
SLANG_RAW("\n")
28214
0
SLANG_RAW("    /// Performs component-wise remainder operation between two cooperative vectors.\n")
28215
0
SLANG_RAW("    /// @param other The cooperative vector to compute the remainder with.\n")
28216
0
SLANG_RAW("    /// @return A new cooperative vector containing the remainder of the division between corresponding components.\n")
28217
0
SLANG_RAW("    [ForceInline]\n")
28218
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28219
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28220
0
SLANG_RAW("    This mod(This other)\n")
28221
0
SLANG_RAW("    {\n")
28222
0
SLANG_RAW("        __target_switch\n")
28223
0
SLANG_RAW("        {\n")
28224
0
SLANG_RAW("        case hlsl:\n")
28225
0
SLANG_RAW("            __intrinsic_asm \"$0 % $1\";\n")
28226
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28227
0
SLANG_RAW("            This ret = this;\n")
28228
0
SLANG_RAW("            ret.__mutMod(other);\n")
28229
0
SLANG_RAW("            return ret;\n")
28230
0
SLANG_RAW("        default:\n")
28231
0
SLANG_RAW("            This ret;\n")
28232
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
28233
0
SLANG_RAW("                ret[i] = this[i] % other[i];\n")
28234
0
SLANG_RAW("            return ret;\n")
28235
0
SLANG_RAW("        }\n")
28236
0
SLANG_RAW("    }\n")
28237
0
SLANG_RAW("\n")
28238
0
SLANG_RAW("    __intrinsic_op(")
28239
0
SLANG_SPLICE(kIROp_Neg
28240
0
)
28241
0
SLANG_RAW(")\n")
28242
0
SLANG_RAW("    static This __pureNeg(This other);\n")
28243
0
SLANG_RAW("\n")
28244
0
SLANG_RAW("    /// Returns a new cooperative vector where each component has its sign negated.\n")
28245
0
SLANG_RAW("    /// @return A new cooperative vector containing the negated values.\n")
28246
0
SLANG_RAW("    //[ForceInline]\n")
28247
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28248
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28249
0
SLANG_RAW("    This neg()\n")
28250
0
SLANG_RAW("    {\n")
28251
0
SLANG_RAW("        __target_switch\n")
28252
0
SLANG_RAW("        {\n")
28253
0
SLANG_RAW("        case hlsl:\n")
28254
0
SLANG_RAW("            __intrinsic_asm \"-$0\";\n")
28255
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28256
0
SLANG_RAW("            This ret = this;\n")
28257
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
28258
0
SLANG_RAW("                ret[i] = -this[i];\n")
28259
0
SLANG_RAW("            return ret;\n")
28260
0
SLANG_RAW("        default: return __pureNeg(this);\n")
28261
0
SLANG_RAW("        }\n")
28262
0
SLANG_RAW("    }\n")
28263
0
SLANG_RAW("\n")
28264
0
SLANG_RAW("    [mutating]\n")
28265
0
SLANG_RAW("    [require(hlsl)]\n")
28266
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28267
0
SLANG_RAW("    void __mutScalarMul(T t)\n")
28268
0
SLANG_RAW("    {\n")
28269
0
SLANG_RAW("        __target_switch\n")
28270
0
SLANG_RAW("        {\n")
28271
0
SLANG_RAW("        case hlsl: __intrinsic_asm \"$0 *= $1\";\n")
28272
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".ScalarMultiply\";\n")
28273
0
SLANG_RAW("        }\n")
28274
0
SLANG_RAW("    }\n")
28275
0
SLANG_RAW("\n")
28276
0
SLANG_RAW("    [mutating]\n")
28277
0
SLANG_RAW("    [require(hlsl)]\n")
28278
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28279
0
SLANG_RAW("    void __mutMin(This other)\n")
28280
0
SLANG_RAW("    {\n")
28281
0
SLANG_RAW("        __target_switch\n")
28282
0
SLANG_RAW("        {\n")
28283
0
SLANG_RAW("        case hlsl: static_assert(false, \"Not supported\");\n")
28284
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Min\";\n")
28285
0
SLANG_RAW("        }\n")
28286
0
SLANG_RAW("    }\n")
28287
0
SLANG_RAW("\n")
28288
0
SLANG_RAW("    [mutating]\n")
28289
0
SLANG_RAW("    [require(hlsl)]\n")
28290
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28291
0
SLANG_RAW("    void __mutMax(This other)\n")
28292
0
SLANG_RAW("    {\n")
28293
0
SLANG_RAW("        __target_switch\n")
28294
0
SLANG_RAW("        {\n")
28295
0
SLANG_RAW("        case hlsl: static_assert(false, \"Not supported\");\n")
28296
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Max\";\n")
28297
0
SLANG_RAW("        }\n")
28298
0
SLANG_RAW("    }\n")
28299
0
SLANG_RAW("\n")
28300
0
SLANG_RAW("    [mutating]\n")
28301
0
SLANG_RAW("    [require(hlsl)]\n")
28302
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28303
0
SLANG_RAW("    void __mutClamp(This minVal, This maxVal)\n")
28304
0
SLANG_RAW("    {\n")
28305
0
SLANG_RAW("        __target_switch\n")
28306
0
SLANG_RAW("        {\n")
28307
0
SLANG_RAW("        case hlsl: static_assert(false, \"Not supported\");\n")
28308
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Clamp\";\n")
28309
0
SLANG_RAW("        }\n")
28310
0
SLANG_RAW("    }\n")
28311
0
SLANG_RAW("\n")
28312
0
SLANG_RAW("    //\n")
28313
0
SLANG_RAW("    // Internal utilities for loading and storing\n")
28314
0
SLANG_RAW("    //\n")
28315
0
SLANG_RAW("\n")
28316
0
SLANG_RAW("    [mutating]\n")
28317
0
SLANG_RAW("    [ForceInline]\n")
28318
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer)]\n")
28319
0
SLANG_RAW("    [require(hlsl_coopvec_poc, byteaddressbuffer)]\n")
28320
0
SLANG_RAW("    void __Load(const ByteAddressBuffer buffer, uint byteOffset, uint alignment = 0)\n")
28321
0
SLANG_RAW("    {\n")
28322
0
SLANG_RAW("        __target_switch\n")
28323
0
SLANG_RAW("        {\n")
28324
0
SLANG_RAW("        case hlsl:\n")
28325
0
SLANG_RAW("            __intrinsic_asm \"$0 = $1.Load< vector<$[0], $[1]> >($2)\", T, N;\n")
28326
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28327
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
28328
0
SLANG_RAW("        }\n")
28329
0
SLANG_RAW("    }\n")
28330
0
SLANG_RAW("\n")
28331
0
SLANG_RAW("    [mutating]\n")
28332
0
SLANG_RAW("    [ForceInline]\n")
28333
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer_rw)]\n")
28334
0
SLANG_RAW("    [require(hlsl_coopvec_poc, byteaddressbuffer_rw)]\n")
28335
0
SLANG_RAW("    void __Load(const RWByteAddressBuffer buffer, uint byteOffset, uint alignment = 0)\n")
28336
0
SLANG_RAW("    {\n")
28337
0
SLANG_RAW("        __target_switch\n")
28338
0
SLANG_RAW("        {\n")
28339
0
SLANG_RAW("        case hlsl:\n")
28340
0
SLANG_RAW("            __intrinsic_asm \"$0 = $1.Load< vector<$[0], $[1]> >($2)\", T, N;\n")
28341
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28342
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
28343
0
SLANG_RAW("        }\n")
28344
0
SLANG_RAW("    }\n")
28345
0
SLANG_RAW("\n")
28346
0
SLANG_RAW("    __generic<let M : int>\n")
28347
0
SLANG_RAW("    [mutating]\n")
28348
0
SLANG_RAW("    // Careful, this takes the offset in elements\n")
28349
0
SLANG_RAW("    [ForceInline]\n")
28350
0
SLANG_RAW("    [require(hlsl)]\n")
28351
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28352
0
SLANG_RAW("    void __Load(__constref groupshared T buffer[M], uint elemOffset)\n")
28353
0
SLANG_RAW("    {\n")
28354
0
SLANG_RAW("        static_assert(N <= M, \"The given groupshared array is smaller than the given CoopVec\");\n")
28355
0
SLANG_RAW("        __target_switch\n")
28356
0
SLANG_RAW("        {\n")
28357
0
SLANG_RAW("        case hlsl:\n")
28358
0
SLANG_RAW("            [ForceUnroll]\n")
28359
0
SLANG_RAW("            for(int i = 0; i < N; ++i)\n")
28360
0
SLANG_RAW("                this[i] = buffer[i + elemOffset];\n")
28361
0
SLANG_RAW("            return;\n")
28362
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28363
0
SLANG_RAW("            __intrinsic_asm \".Load\";\n")
28364
0
SLANG_RAW("        }\n")
28365
0
SLANG_RAW("    }\n")
28366
0
SLANG_RAW("\n")
28367
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer_rw)]\n")
28368
0
SLANG_RAW("    [require(hlsl_coopvec_poc, byteaddressbuffer_rw)]\n")
28369
0
SLANG_RAW("    void __Store(RWByteAddressBuffer buffer, uint byteOffset, uint alignment = 0)\n")
28370
0
SLANG_RAW("    {\n")
28371
0
SLANG_RAW("        __target_switch\n")
28372
0
SLANG_RAW("        {\n")
28373
0
SLANG_RAW("        case hlsl: static_assert(false, \"Not supported\");\n")
28374
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Store\";\n")
28375
0
SLANG_RAW("        }\n")
28376
0
SLANG_RAW("    }\n")
28377
0
SLANG_RAW("\n")
28378
0
SLANG_RAW("    __generic<let M : int>\n")
28379
0
SLANG_RAW("    [require(hlsl)]\n")
28380
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28381
0
SLANG_RAW("    // Careful, this takes the offset in elements\n")
28382
0
SLANG_RAW("    void __Store(__ref groupshared T buffer[M], uint elemOffset)\n")
28383
0
SLANG_RAW("    {\n")
28384
0
SLANG_RAW("        __target_switch\n")
28385
0
SLANG_RAW("        {\n")
28386
0
SLANG_RAW("        case hlsl: static_assert(false, \"Not supported\");\n")
28387
0
SLANG_RAW("        case hlsl_coopvec_poc: __intrinsic_asm \".Store\";\n")
28388
0
SLANG_RAW("        }\n")
28389
0
SLANG_RAW("    }\n")
28390
0
SLANG_RAW("\n")
28391
28392
0
static const struct {
28393
0
    bool isRW;
28394
0
    char const* type;
28395
0
} kByteAddressBufferCases[] =
28396
0
{
28397
0
    {true, "RWByteAddressBuffer"},
28398
0
    {false, "ByteAddressBuffer"}
28399
0
};
28400
0
for(auto buffer : kByteAddressBufferCases) {
28401
0
SLANG_RAW("#line 25736 \"hlsl.meta.slang\"")
28402
0
SLANG_RAW("\n")
28403
0
SLANG_RAW("    [mutating]\n")
28404
0
SLANG_RAW("    [ForceInline]\n")
28405
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer_rw)]\n")
28406
0
SLANG_RAW("    [require(hlsl_coopvec_poc, byteaddressbuffer_rw)]\n")
28407
0
SLANG_RAW("    void __mutMatMul<U : __BuiltinArithmeticType, let K : int>(\n")
28408
0
SLANG_RAW("        CoopVec<U, K> input, uint inputInterpretationHLSL,\n")
28409
0
SLANG_RAW("        ")
28410
0
SLANG_SPLICE(buffer.type
28411
0
)
28412
0
SLANG_RAW(" matrix, uint matrixOffset, uint matrixInterpretationHLSL,\n")
28413
0
SLANG_RAW("        uint m, uint k, uint memoryLayoutHLSL, bool transpose, uint matrixStride)\n")
28414
0
SLANG_RAW("    {\n")
28415
0
SLANG_RAW("        __target_switch\n")
28416
0
SLANG_RAW("        {\n")
28417
0
SLANG_RAW("        case hlsl:\n")
28418
0
SLANG_RAW("            if (__isFloat<T>() || __isSignedInt<T>())\n")
28419
0
SLANG_RAW("            {\n")
28420
0
SLANG_RAW("                if (__isFloat<U>() || __isSignedInt<U>())\n")
28421
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMul($0, false,  $1, false, $2,  $3, $4, $5,  $6, $7, $8, $9, $10)\";\n")
28422
0
SLANG_RAW("                else\n")
28423
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMul($0, false,  $1,  true, $2,  $3, $4, $5,  $6, $7, $8, $9, $10)\";\n")
28424
0
SLANG_RAW("            }\n")
28425
0
SLANG_RAW("            else\n")
28426
0
SLANG_RAW("            {\n")
28427
0
SLANG_RAW("                if (__isFloat<U>() || __isSignedInt<U>())\n")
28428
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMul($0, true,  $1, false, $2,  $3, $4, $5,  $6, $7, $8, $9, $10)\";\n")
28429
0
SLANG_RAW("                else\n")
28430
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMul($0, true,  $1,  true, $2,  $3, $4, $5,  $6, $7, $8, $9, $10)\";\n")
28431
0
SLANG_RAW("            }\n")
28432
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28433
0
SLANG_RAW("            __intrinsic_asm \".MatMul\";\n")
28434
0
SLANG_RAW("        }\n")
28435
0
SLANG_RAW("    }\n")
28436
0
SLANG_RAW("\n")
28437
0
SLANG_RAW("    [mutating]\n")
28438
0
SLANG_RAW("    [ForceInline]\n")
28439
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer_rw)]\n")
28440
0
SLANG_RAW("    [require(hlsl_coopvec_poc, byteaddressbuffer_rw)]\n")
28441
0
SLANG_RAW("    void __mutMatMulAdd<U : __BuiltinArithmeticType, let K : int>(\n")
28442
0
SLANG_RAW("        CoopVec<U, K> input, uint inputInterpretationHLSL,\n")
28443
0
SLANG_RAW("        ")
28444
0
SLANG_SPLICE(buffer.type
28445
0
)
28446
0
SLANG_RAW(" matrix, uint matrixOffset, uint matrixInterpretationHLSL,\n")
28447
0
SLANG_RAW("        ")
28448
0
SLANG_SPLICE(buffer.type
28449
0
)
28450
0
SLANG_RAW(" bias, uint biasOffset, uint biasInterpretationHLSL,\n")
28451
0
SLANG_RAW("        uint m, uint k, uint memoryLayoutHLSL, bool transpose, uint matrixStride)\n")
28452
0
SLANG_RAW("    {\n")
28453
0
SLANG_RAW("        __target_switch\n")
28454
0
SLANG_RAW("        {\n")
28455
0
SLANG_RAW("        case hlsl:\n")
28456
0
SLANG_RAW("            if (__isFloat<T>() || __isSignedInt<T>())\n")
28457
0
SLANG_RAW("            {\n")
28458
0
SLANG_RAW("                if (__isFloat<U>() || __isSignedInt<U>())\n")
28459
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMulAdd($0, false,  $1, false, $2,  $3, $4, $5,  $9, $10, $11, $12, $13,  $6, $7, $8)\";\n")
28460
0
SLANG_RAW("                else\n")
28461
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMulAdd($0, false,  $1,  true, $2,  $3, $4, $5,  $9, $10, $11, $12, $13,  $6, $7, $8)\";\n")
28462
0
SLANG_RAW("            }\n")
28463
0
SLANG_RAW("            else\n")
28464
0
SLANG_RAW("            {\n")
28465
0
SLANG_RAW("                if (__isFloat<U>() || __isSignedInt<U>())\n")
28466
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMulAdd($0, true,  $1, false, $2,  $3, $4, $5,  $9, $10, $11, $12, $13,  $6, $7, $8)\";\n")
28467
0
SLANG_RAW("                else\n")
28468
0
SLANG_RAW("                    __intrinsic_asm \"__builtin_MatVecMulAdd($0, true,  $1,  true, $2,  $3, $4, $5,  $9, $10, $11, $12, $13,  $6, $7, $8)\";\n")
28469
0
SLANG_RAW("            }\n")
28470
0
SLANG_RAW("        case hlsl_coopvec_poc:\n")
28471
0
SLANG_RAW("            __intrinsic_asm \".MatMulAdd\";\n")
28472
0
SLANG_RAW("        }\n")
28473
0
SLANG_RAW("    }\n")
28474
0
SLANG_RAW("\n")
28475
0
SLANG_RAW("    /// Multiply the given input Cooperative vector with the given matrix and accumulate the result into this vector.\n")
28476
0
SLANG_RAW("    /// @param input The input Cooperative vector to multiply with the matrix.\n")
28477
0
SLANG_RAW("    /// @param inputInterpretation Specifies how to interpret the values in the input vector (e.g. as packed values).\n")
28478
0
SLANG_RAW("    /// @param k The number of columns in the matrix.\n")
28479
0
SLANG_RAW("    /// @param matrix The matrix buffer to multiply with.\n")
28480
0
SLANG_RAW("    /// @param matrixOffset Byte offset into the matrix buffer.\n")
28481
0
SLANG_RAW("    /// @param matrixInterpretation Specifies how to interpret the values in the matrix.\n")
28482
0
SLANG_RAW("    /// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
28483
0
SLANG_RAW("    /// @param transpose Whether to transpose the matrix before multiplication.\n")
28484
0
SLANG_RAW("    /// @param matrixStride The stride between matrix rows/columns in bytes.\n")
28485
0
SLANG_RAW("    /// @remarks Unlike matMulAccum, this function supports packed input interpretations where multiple values\n")
28486
0
SLANG_RAW("    /// can be packed into each element of the input vector. The k parameter specifies the actual number of\n")
28487
0
SLANG_RAW("    /// values to use from the packed input.\n")
28488
0
SLANG_RAW("    [mutating]\n")
28489
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28490
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28491
0
SLANG_RAW("    void matMulAccumPacked<U : __BuiltinArithmeticType, let PackedK : int>(\n")
28492
0
SLANG_RAW("        CoopVec<U, PackedK> input,\n")
28493
0
SLANG_RAW("        constexpr CoopVecComponentType inputInterpretation,\n")
28494
0
SLANG_RAW("        constexpr int k,\n")
28495
0
SLANG_RAW("        ")
28496
0
SLANG_SPLICE(buffer.type
28497
0
)
28498
0
SLANG_RAW(" matrix,\n")
28499
0
SLANG_RAW("        int32_t matrixOffset,\n")
28500
0
SLANG_RAW("        constexpr CoopVecComponentType matrixInterpretation,\n")
28501
0
SLANG_RAW("        constexpr CoopVecMatrixLayout memoryLayout,\n")
28502
0
SLANG_RAW("        constexpr bool transpose,\n")
28503
0
SLANG_RAW("        constexpr uint matrixStride\n")
28504
0
SLANG_RAW("    )\n")
28505
0
SLANG_RAW("    {\n")
28506
0
SLANG_RAW("        static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
28507
0
SLANG_RAW("                    , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
28508
0
SLANG_RAW("        static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
28509
0
SLANG_RAW("                    || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
28510
0
SLANG_RAW("                    , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
28511
0
SLANG_RAW("\n")
28512
0
SLANG_RAW("        __target_switch\n")
28513
0
SLANG_RAW("        {\n")
28514
0
SLANG_RAW("        case hlsl:\n")
28515
0
SLANG_RAW("            let inputInterpretationHLSL = __getHLSLCoopVecComponentType(inputInterpretation);\n")
28516
0
SLANG_RAW("            let matrixInterpretationHLSL = __getHLSLCoopVecComponentType(matrixInterpretation);\n")
28517
0
SLANG_RAW("            let memoryLayoutHLSL = __getHLSLCoopVecMatrixLayout(memoryLayout);\n")
28518
0
SLANG_RAW("            This temp = this;\n")
28519
0
SLANG_RAW("            temp.__mutMatMul(\n")
28520
0
SLANG_RAW("                input,\n")
28521
0
SLANG_RAW("                inputInterpretationHLSL,\n")
28522
0
SLANG_RAW("                matrix,\n")
28523
0
SLANG_RAW("                matrixOffset,\n")
28524
0
SLANG_RAW("                matrixInterpretationHLSL,\n")
28525
0
SLANG_RAW("                N,\n")
28526
0
SLANG_RAW("                k,\n")
28527
0
SLANG_RAW("                memoryLayoutHLSL,\n")
28528
0
SLANG_RAW("                transpose,\n")
28529
0
SLANG_RAW("                matrixStride\n")
28530
0
SLANG_RAW("            );\n")
28531
0
SLANG_RAW("            this.__mutAdd(temp);\n")
28532
0
SLANG_RAW("        default: this = this + coopVecMatMulPacked<T, N, PackedK, U>(\n")
28533
0
SLANG_RAW("                input,\n")
28534
0
SLANG_RAW("                inputInterpretation,\n")
28535
0
SLANG_RAW("                k,\n")
28536
0
SLANG_RAW("                matrix,\n")
28537
0
SLANG_RAW("                matrixOffset,\n")
28538
0
SLANG_RAW("                matrixInterpretation,\n")
28539
0
SLANG_RAW("                memoryLayout,\n")
28540
0
SLANG_RAW("                transpose,\n")
28541
0
SLANG_RAW("                matrixStride\n")
28542
0
SLANG_RAW("            );\n")
28543
0
SLANG_RAW("        }\n")
28544
0
SLANG_RAW("    }\n")
28545
0
SLANG_RAW("\n")
28546
0
SLANG_RAW("    /// Accumulate the result from a matrix multiplication between an input Cooperative vector and a matrix.\n")
28547
0
SLANG_RAW("    /// @param input The input Cooperative vector to multiply with the matrix.\n")
28548
0
SLANG_RAW("    /// @param inputInterpretation Specifies how to interpret the values in the input vector (e.g. as 8-bit integers, 16-bit floats, etc).\n")
28549
0
SLANG_RAW("    /// @param matrix The matrix to multiply with the input vector.\n")
28550
0
SLANG_RAW("    /// @param matrixOffset Byte offset into the matrix buffer.\n")
28551
0
SLANG_RAW("    /// @param matrixInterpretation Specifies how to interpret the values in the matrix (e.g. as 8-bit integers, 16-bit floats, etc).\n")
28552
0
SLANG_RAW("    /// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
28553
0
SLANG_RAW("    /// @param transpose Whether to transpose the matrix before multiplication.\n")
28554
0
SLANG_RAW("    /// @param matrixStride The stride in bytes between rows/columns of the matrix.\n")
28555
0
SLANG_RAW("    [mutating]\n")
28556
0
SLANG_RAW("    [ForceInline]\n")
28557
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28558
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28559
0
SLANG_RAW("    void matMulAccum<U : __BuiltinArithmeticType, let K : int>(\n")
28560
0
SLANG_RAW("        CoopVec<U, K> input,\n")
28561
0
SLANG_RAW("        constexpr CoopVecComponentType inputInterpretation,\n")
28562
0
SLANG_RAW("        ")
28563
0
SLANG_SPLICE(buffer.type
28564
0
)
28565
0
SLANG_RAW(" matrix,\n")
28566
0
SLANG_RAW("        int32_t matrixOffset,\n")
28567
0
SLANG_RAW("        constexpr CoopVecComponentType matrixInterpretation,\n")
28568
0
SLANG_RAW("        constexpr CoopVecMatrixLayout memoryLayout,\n")
28569
0
SLANG_RAW("        constexpr bool transpose,\n")
28570
0
SLANG_RAW("        constexpr uint matrixStride\n")
28571
0
SLANG_RAW("    )\n")
28572
0
SLANG_RAW("    {\n")
28573
0
SLANG_RAW("        static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
28574
0
SLANG_RAW("                    , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
28575
0
SLANG_RAW("        this.matMulAccumPacked<U, K>(\n")
28576
0
SLANG_RAW("            input,\n")
28577
0
SLANG_RAW("            inputInterpretation,\n")
28578
0
SLANG_RAW("            K,\n")
28579
0
SLANG_RAW("            matrix,\n")
28580
0
SLANG_RAW("            matrixOffset,\n")
28581
0
SLANG_RAW("            matrixInterpretation,\n")
28582
0
SLANG_RAW("            memoryLayout,\n")
28583
0
SLANG_RAW("            transpose,\n")
28584
0
SLANG_RAW("            matrixStride\n")
28585
0
SLANG_RAW("        );\n")
28586
0
SLANG_RAW("    }\n")
28587
0
SLANG_RAW("\n")
28588
0
SLANG_RAW("    [mutating]\n")
28589
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28590
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28591
0
SLANG_RAW("    void matMulAddAccumPacked<U : __BuiltinArithmeticType, let PackedK : int>(\n")
28592
0
SLANG_RAW("        CoopVec<U, PackedK> input,\n")
28593
0
SLANG_RAW("        constexpr CoopVecComponentType inputInterpretation,\n")
28594
0
SLANG_RAW("        constexpr int k,\n")
28595
0
SLANG_RAW("        ")
28596
0
SLANG_SPLICE(buffer.type
28597
0
)
28598
0
SLANG_RAW(" matrix,\n")
28599
0
SLANG_RAW("        int32_t matrixOffset,\n")
28600
0
SLANG_RAW("        constexpr CoopVecComponentType matrixInterpretation,\n")
28601
0
SLANG_RAW("        ")
28602
0
SLANG_SPLICE(buffer.type
28603
0
)
28604
0
SLANG_RAW(" bias,\n")
28605
0
SLANG_RAW("        int32_t biasOffset,\n")
28606
0
SLANG_RAW("        constexpr CoopVecComponentType biasInterpretation,\n")
28607
0
SLANG_RAW("        constexpr CoopVecMatrixLayout memoryLayout,\n")
28608
0
SLANG_RAW("        constexpr bool transpose,\n")
28609
0
SLANG_RAW("        constexpr uint matrixStride\n")
28610
0
SLANG_RAW("    )\n")
28611
0
SLANG_RAW("    {\n")
28612
0
SLANG_RAW("        static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
28613
0
SLANG_RAW("                    , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
28614
0
SLANG_RAW("        static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
28615
0
SLANG_RAW("                    || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
28616
0
SLANG_RAW("                    , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
28617
0
SLANG_RAW("\n")
28618
0
SLANG_RAW("        __target_switch\n")
28619
0
SLANG_RAW("        {\n")
28620
0
SLANG_RAW("        case hlsl:\n")
28621
0
SLANG_RAW("            let inputInterpretationHLSL = __getHLSLCoopVecComponentType(inputInterpretation);\n")
28622
0
SLANG_RAW("            let matrixInterpretationHLSL = __getHLSLCoopVecComponentType(matrixInterpretation);\n")
28623
0
SLANG_RAW("            let biasInterpretationHLSL = __getHLSLCoopVecComponentType(biasInterpretation);\n")
28624
0
SLANG_RAW("            let memoryLayoutHLSL = __getHLSLCoopVecMatrixLayout(memoryLayout);\n")
28625
0
SLANG_RAW("            This temp = this;\n")
28626
0
SLANG_RAW("            temp.__mutMatMulAdd(\n")
28627
0
SLANG_RAW("                input,\n")
28628
0
SLANG_RAW("                inputInterpretationHLSL,\n")
28629
0
SLANG_RAW("                matrix,\n")
28630
0
SLANG_RAW("                matrixOffset,\n")
28631
0
SLANG_RAW("                matrixInterpretationHLSL,\n")
28632
0
SLANG_RAW("                bias,\n")
28633
0
SLANG_RAW("                biasOffset,\n")
28634
0
SLANG_RAW("                biasInterpretationHLSL,\n")
28635
0
SLANG_RAW("                N,\n")
28636
0
SLANG_RAW("                k,\n")
28637
0
SLANG_RAW("                memoryLayoutHLSL,\n")
28638
0
SLANG_RAW("                transpose,\n")
28639
0
SLANG_RAW("                matrixStride\n")
28640
0
SLANG_RAW("            );\n")
28641
0
SLANG_RAW("            this.__mutAdd(temp);\n")
28642
0
SLANG_RAW("        default: this = this + coopVecMatMulAddPacked<T, N, PackedK, U>(\n")
28643
0
SLANG_RAW("            input,\n")
28644
0
SLANG_RAW("            inputInterpretation,\n")
28645
0
SLANG_RAW("            k,\n")
28646
0
SLANG_RAW("            matrix,\n")
28647
0
SLANG_RAW("            matrixOffset,\n")
28648
0
SLANG_RAW("            matrixInterpretation,\n")
28649
0
SLANG_RAW("            bias,\n")
28650
0
SLANG_RAW("            biasOffset,\n")
28651
0
SLANG_RAW("            biasInterpretation,\n")
28652
0
SLANG_RAW("            memoryLayout,\n")
28653
0
SLANG_RAW("            transpose,\n")
28654
0
SLANG_RAW("            matrixStride\n")
28655
0
SLANG_RAW("            );\n")
28656
0
SLANG_RAW("        }\n")
28657
0
SLANG_RAW("    }\n")
28658
0
SLANG_RAW("\n")
28659
0
SLANG_RAW("    /// Performs matrix multiplication and accumulation with bias: this += input * matrix + bias\n")
28660
0
SLANG_RAW("    /// @param input The input vector to multiply with the matrix\n")
28661
0
SLANG_RAW("    /// @param inputInterpretation How to interpret the input vector elements (must not be packed)\n")
28662
0
SLANG_RAW("    /// @param matrix The matrix buffer to multiply with\n")
28663
0
SLANG_RAW("    /// @param matrixOffset Byte offset into the matrix buffer\n")
28664
0
SLANG_RAW("    /// @param matrixInterpretation How to interpret the matrix elements\n")
28665
0
SLANG_RAW("    /// @param bias The bias buffer to add\n")
28666
0
SLANG_RAW("    /// @param biasOffset Byte offset into the bias buffer\n")
28667
0
SLANG_RAW("    /// @param biasInterpretation How to interpret the bias elements\n")
28668
0
SLANG_RAW("    /// @param memoryLayout Memory layout of the matrix (row or column major)\n")
28669
0
SLANG_RAW("    /// @param transpose Whether to transpose the matrix before multiplication\n")
28670
0
SLANG_RAW("    /// @param matrixStride Stride between matrix rows/columns in bytes\n")
28671
0
SLANG_RAW("    /// @remark The key difference from matMulAddAccumPacked is that this method enforces k must equal the input vector length,\n")
28672
0
SLANG_RAW("    /// while matMulAddAccumPacked allows k to be specified independently for packed interpretations.\n")
28673
0
SLANG_RAW("    [mutating]\n")
28674
0
SLANG_RAW("    [ForceInline]\n")
28675
0
SLANG_RAW("    [require(cooperative_vector)]\n")
28676
0
SLANG_RAW("    [require(hlsl_coopvec_poc)]\n")
28677
0
SLANG_RAW("    void matMulAddAccum<U : __BuiltinArithmeticType, let K : int>(\n")
28678
0
SLANG_RAW("        CoopVec<U, K> input,\n")
28679
0
SLANG_RAW("        constexpr CoopVecComponentType inputInterpretation,\n")
28680
0
SLANG_RAW("        ")
28681
0
SLANG_SPLICE(buffer.type
28682
0
)
28683
0
SLANG_RAW(" matrix,\n")
28684
0
SLANG_RAW("        int32_t matrixOffset,\n")
28685
0
SLANG_RAW("        constexpr CoopVecComponentType matrixInterpretation,\n")
28686
0
SLANG_RAW("        ")
28687
0
SLANG_SPLICE(buffer.type
28688
0
)
28689
0
SLANG_RAW(" bias,\n")
28690
0
SLANG_RAW("        int32_t biasOffset,\n")
28691
0
SLANG_RAW("        constexpr CoopVecComponentType biasInterpretation,\n")
28692
0
SLANG_RAW("        constexpr CoopVecMatrixLayout memoryLayout,\n")
28693
0
SLANG_RAW("        constexpr bool transpose,\n")
28694
0
SLANG_RAW("        constexpr uint matrixStride\n")
28695
0
SLANG_RAW("    )\n")
28696
0
SLANG_RAW("    {\n")
28697
0
SLANG_RAW("        static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
28698
0
SLANG_RAW("                    , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
28699
0
SLANG_RAW("        this.matMulAddAccumPacked<U, K>(\n")
28700
0
SLANG_RAW("            input,\n")
28701
0
SLANG_RAW("            inputInterpretation,\n")
28702
0
SLANG_RAW("            K,\n")
28703
0
SLANG_RAW("            matrix,\n")
28704
0
SLANG_RAW("            matrixOffset,\n")
28705
0
SLANG_RAW("            matrixInterpretation,\n")
28706
0
SLANG_RAW("            bias,\n")
28707
0
SLANG_RAW("            biasOffset,\n")
28708
0
SLANG_RAW("            biasInterpretation,\n")
28709
0
SLANG_RAW("            memoryLayout,\n")
28710
0
SLANG_RAW("            transpose,\n")
28711
0
SLANG_RAW("            matrixStride\n")
28712
0
SLANG_RAW("        );\n")
28713
0
SLANG_RAW("    }\n")
28714
0
SLANG_RAW("\n")
28715
0
SLANG_RAW("    [ForceInline]\n")
28716
0
SLANG_RAW("    [require(hlsl, byteaddressbuffer_rw)]\n")
28717
0
SLANG_RAW("    void __OuterProductAccumulate<let K : int>(\n")
28718
0
SLANG_RAW("        CoopVec<T, K> b,\n")
28719
0
SLANG_RAW("        ")
28720
0
SLANG_SPLICE(buffer.type
28721
0
)
28722
0
SLANG_RAW(" matrix,\n")
28723
0
SLANG_RAW("        int32_t matrixOffset,\n")
28724
0
SLANG_RAW("        uint matrixStride,\n")
28725
0
SLANG_RAW("        uint memoryLayout,\n")
28726
0
SLANG_RAW("        uint matrixInterpretation,\n")
28727
0
SLANG_RAW("    )\n")
28728
0
SLANG_RAW("    {\n")
28729
0
SLANG_RAW("        __target_switch\n")
28730
0
SLANG_RAW("        {\n")
28731
0
SLANG_RAW("        case hlsl:\n")
28732
0
SLANG_RAW("            __intrinsic_asm \"__builtin_OuterProductAccumulate($0, $1, $2, $3, $6, $5, $4)\";\n")
28733
0
SLANG_RAW("        }\n")
28734
0
SLANG_RAW("    }\n")
28735
0
SLANG_RAW("\n")
28736
0
SLANG_RAW("\n")
28737
28738
0
}
28739
0
SLANG_RAW("#line 26043 \"hlsl.meta.slang\"")
28740
0
SLANG_RAW("\n")
28741
0
SLANG_RAW("}\n")
28742
0
SLANG_RAW("\n")
28743
0
SLANG_RAW("__intrinsic_op(")
28744
0
SLANG_SPLICE(kIROp_MakeCoopVectorFromValuePack
28745
0
)
28746
0
SLANG_RAW(")\n")
28747
0
SLANG_RAW("CoopVec<T, N> __makeCoopVec<T : __BuiltinArithmeticType, let N : int, each U>(expand each U args);\n")
28748
0
SLANG_RAW("\n")
28749
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
28750
0
SLANG_RAW("__intrinsic_op(")
28751
0
SLANG_SPLICE(kIROp_IntCast
28752
0
)
28753
0
SLANG_RAW(")\n")
28754
0
SLANG_RAW("[require(cooperative_vector)]\n")
28755
0
SLANG_RAW("CoopVec<T,N> __int_cast(CoopVec<U,N> val);\n")
28756
0
SLANG_RAW("\n")
28757
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
28758
0
SLANG_RAW("__intrinsic_op(")
28759
0
SLANG_SPLICE(kIROp_FloatCast
28760
0
)
28761
0
SLANG_RAW(")\n")
28762
0
SLANG_RAW("[require(cooperative_vector)]\n")
28763
0
SLANG_RAW("CoopVec<T,N> __real_cast(CoopVec<U,N> val);\n")
28764
0
SLANG_RAW("\n")
28765
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
28766
0
SLANG_RAW("__intrinsic_op(")
28767
0
SLANG_SPLICE(kIROp_CastIntToFloat
28768
0
)
28769
0
SLANG_RAW(")\n")
28770
0
SLANG_RAW("[require(cooperative_vector)]\n")
28771
0
SLANG_RAW("CoopVec<T,N> __int_to_float_cast(CoopVec<U,N> val);\n")
28772
0
SLANG_RAW("\n")
28773
0
SLANG_RAW("__generic<T:__BuiltinArithmeticType, U:__BuiltinArithmeticType, let N : int>\n")
28774
0
SLANG_RAW("__intrinsic_op(")
28775
0
SLANG_SPLICE(kIROp_CastFloatToInt
28776
0
)
28777
0
SLANG_RAW(")\n")
28778
0
SLANG_RAW("[require(cooperative_vector)]\n")
28779
0
SLANG_RAW("CoopVec<T,N> __float_to_int_cast(CoopVec<U,N> val);\n")
28780
0
SLANG_RAW("\n")
28781
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
28782
0
SLANG_RAW("[ForceInline]\n")
28783
0
SLANG_RAW("[require(cooperative_vector)]\n")
28784
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28785
0
SLANG_RAW("CoopVec<T, N> operator *(CoopVec<T, N> lhs, const T rhs)\n")
28786
0
SLANG_RAW("{\n")
28787
0
SLANG_RAW("    __target_switch\n")
28788
0
SLANG_RAW("    {\n")
28789
0
SLANG_RAW("    case spirv:\n")
28790
0
SLANG_RAW("        if (__isFloat<T>())\n")
28791
0
SLANG_RAW("        {\n")
28792
0
SLANG_RAW("            return spirv_asm\n")
28793
0
SLANG_RAW("            {\n")
28794
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpVectorTimesScalar $lhs $rhs;\n")
28795
0
SLANG_RAW("            };\n")
28796
0
SLANG_RAW("        }\n")
28797
0
SLANG_RAW("        else\n")
28798
0
SLANG_RAW("        {\n")
28799
0
SLANG_RAW("            for (int i = 0; i < N; ++i)\n")
28800
0
SLANG_RAW("            {\n")
28801
0
SLANG_RAW("                lhs[i] *= rhs;\n")
28802
0
SLANG_RAW("            }\n")
28803
0
SLANG_RAW("            return lhs;\n")
28804
0
SLANG_RAW("        }\n")
28805
0
SLANG_RAW("    case hlsl:\n")
28806
0
SLANG_RAW("        __intrinsic_asm \"$0 * $1\";\n")
28807
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28808
0
SLANG_RAW("        CoopVec<T, N> ret = lhs;\n")
28809
0
SLANG_RAW("        ret.__mutScalarMul(rhs);\n")
28810
0
SLANG_RAW("        return ret;\n")
28811
0
SLANG_RAW("    default:\n")
28812
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
28813
0
SLANG_RAW("        {\n")
28814
0
SLANG_RAW("            lhs[i] *= rhs;\n")
28815
0
SLANG_RAW("        }\n")
28816
0
SLANG_RAW("        return lhs;\n")
28817
0
SLANG_RAW("    }\n")
28818
0
SLANG_RAW("}\n")
28819
0
SLANG_RAW("\n")
28820
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let N : int>\n")
28821
0
SLANG_RAW("[ForceInline]\n")
28822
0
SLANG_RAW("[require(cooperative_vector)]\n")
28823
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28824
0
SLANG_RAW("CoopVec<T, N> operator *(const T lhs, CoopVec<T, N> rhs)\n")
28825
0
SLANG_RAW("{\n")
28826
0
SLANG_RAW("    return rhs * lhs;\n")
28827
0
SLANG_RAW("}\n")
28828
0
SLANG_RAW("\n")
28829
0
SLANG_RAW("[ForceInline]\n")
28830
0
SLANG_RAW("[require(cooperative_vector)]\n")
28831
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28832
0
SLANG_RAW("[require(optix_coopvec)]\n")
28833
0
SLANG_RAW("CoopVec<T, N> min<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> y)\n")
28834
0
SLANG_RAW("{\n")
28835
0
SLANG_RAW("    __target_switch\n")
28836
0
SLANG_RAW("    {\n")
28837
0
SLANG_RAW("    case spirv:\n")
28838
0
SLANG_RAW("        return spirv_asm\n")
28839
0
SLANG_RAW("        {\n")
28840
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 FMin $x $y;\n")
28841
0
SLANG_RAW("        };\n")
28842
0
SLANG_RAW("    case hlsl:\n")
28843
0
SLANG_RAW("        __intrinsic_asm \"min($0, $1)\";\n")
28844
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28845
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
28846
0
SLANG_RAW("        ret.__mutMin(y);\n")
28847
0
SLANG_RAW("        return ret;\n")
28848
0
SLANG_RAW("    case optix_coopvec:\n")
28849
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecMin($0, $1)\";\n")
28850
0
SLANG_RAW("    default:\n")
28851
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
28852
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
28853
0
SLANG_RAW("            ret[i] = min(x[i], y[i]);\n")
28854
0
SLANG_RAW("\n")
28855
0
SLANG_RAW("        return ret;\n")
28856
0
SLANG_RAW("    }\n")
28857
0
SLANG_RAW("}\n")
28858
0
SLANG_RAW("\n")
28859
0
SLANG_RAW("[ForceInline]\n")
28860
0
SLANG_RAW("[require(cooperative_vector)]\n")
28861
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28862
0
SLANG_RAW("[require(optix_coopvec)]\n")
28863
0
SLANG_RAW("CoopVec<T, N> max<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> y)\n")
28864
0
SLANG_RAW("{\n")
28865
0
SLANG_RAW("    __target_switch\n")
28866
0
SLANG_RAW("    {\n")
28867
0
SLANG_RAW("    case spirv:\n")
28868
0
SLANG_RAW("        return spirv_asm\n")
28869
0
SLANG_RAW("        {\n")
28870
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 FMax $x $y;\n")
28871
0
SLANG_RAW("        };\n")
28872
0
SLANG_RAW("    case hlsl:\n")
28873
0
SLANG_RAW("        __intrinsic_asm \"max($0, $1)\";\n")
28874
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28875
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
28876
0
SLANG_RAW("        ret.__mutMax(y);\n")
28877
0
SLANG_RAW("        return ret;\n")
28878
0
SLANG_RAW("    case optix_coopvec:\n")
28879
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecMax($0, $1)\";\n")
28880
0
SLANG_RAW("    default:\n")
28881
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
28882
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
28883
0
SLANG_RAW("            ret[i] = max(x[i], y[i]);\n")
28884
0
SLANG_RAW("        return ret;\n")
28885
0
SLANG_RAW("    }\n")
28886
0
SLANG_RAW("}\n")
28887
0
SLANG_RAW("\n")
28888
0
SLANG_RAW("[ForceInline]\n")
28889
0
SLANG_RAW("[require(cooperative_vector)]\n")
28890
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28891
0
SLANG_RAW("CoopVec<T, N> clamp<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> minVal, CoopVec<T, N> maxVal)\n")
28892
0
SLANG_RAW("{\n")
28893
0
SLANG_RAW("    __target_switch\n")
28894
0
SLANG_RAW("    {\n")
28895
0
SLANG_RAW("    case spirv:\n")
28896
0
SLANG_RAW("        return spirv_asm\n")
28897
0
SLANG_RAW("        {\n")
28898
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 FClamp $x $minVal $maxVal;\n")
28899
0
SLANG_RAW("        };\n")
28900
0
SLANG_RAW("    case hlsl:\n")
28901
0
SLANG_RAW("        __intrinsic_asm \"clamp($0, $1, $2)\";\n")
28902
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28903
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
28904
0
SLANG_RAW("        ret.__mutClamp(minVal, maxVal);\n")
28905
0
SLANG_RAW("        return ret;\n")
28906
0
SLANG_RAW("    default:\n")
28907
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
28908
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
28909
0
SLANG_RAW("            ret[i] = clamp(x[i], minVal[i], maxVal[i]);\n")
28910
0
SLANG_RAW("        return ret;\n")
28911
0
SLANG_RAW("    }\n")
28912
0
SLANG_RAW("}\n")
28913
0
SLANG_RAW("\n")
28914
0
SLANG_RAW("[ForceInline]\n")
28915
0
SLANG_RAW("[require(cooperative_vector)]\n")
28916
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28917
0
SLANG_RAW("CoopVec<T, N> min<T : __BuiltinIntegerType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> y)\n")
28918
0
SLANG_RAW("{\n")
28919
0
SLANG_RAW("    __target_switch\n")
28920
0
SLANG_RAW("    {\n")
28921
0
SLANG_RAW("    case spirv:\n")
28922
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
28923
0
SLANG_RAW("        {\n")
28924
0
SLANG_RAW("            return spirv_asm\n")
28925
0
SLANG_RAW("            {\n")
28926
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 SMin $x $y\n")
28927
0
SLANG_RAW("            };\n")
28928
0
SLANG_RAW("        }\n")
28929
0
SLANG_RAW("        else\n")
28930
0
SLANG_RAW("        {\n")
28931
0
SLANG_RAW("            return spirv_asm\n")
28932
0
SLANG_RAW("            {\n")
28933
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 UMin $x $y\n")
28934
0
SLANG_RAW("            };\n")
28935
0
SLANG_RAW("        }\n")
28936
0
SLANG_RAW("    case hlsl:\n")
28937
0
SLANG_RAW("        __intrinsic_asm \"min($0, $1)\";\n")
28938
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28939
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
28940
0
SLANG_RAW("        ret.__mutMin(y);\n")
28941
0
SLANG_RAW("        return ret;\n")
28942
0
SLANG_RAW("    default:\n")
28943
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
28944
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
28945
0
SLANG_RAW("            ret[i] = min(x[i], y[i]);\n")
28946
0
SLANG_RAW("\n")
28947
0
SLANG_RAW("        return ret;\n")
28948
0
SLANG_RAW("    }\n")
28949
0
SLANG_RAW("}\n")
28950
0
SLANG_RAW("\n")
28951
0
SLANG_RAW("// [ForceInline]\n")
28952
0
SLANG_RAW("[require(cooperative_vector)]\n")
28953
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28954
0
SLANG_RAW("CoopVec<T, N> max<T : __BuiltinIntegerType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> y)\n")
28955
0
SLANG_RAW("{\n")
28956
0
SLANG_RAW("    __target_switch\n")
28957
0
SLANG_RAW("    {\n")
28958
0
SLANG_RAW("    case spirv:\n")
28959
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
28960
0
SLANG_RAW("        {\n")
28961
0
SLANG_RAW("            return spirv_asm\n")
28962
0
SLANG_RAW("            {\n")
28963
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 SMax $x $y\n")
28964
0
SLANG_RAW("            };\n")
28965
0
SLANG_RAW("        }\n")
28966
0
SLANG_RAW("        else\n")
28967
0
SLANG_RAW("        {\n")
28968
0
SLANG_RAW("            return spirv_asm\n")
28969
0
SLANG_RAW("            {\n")
28970
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 UMax $x $y\n")
28971
0
SLANG_RAW("            };\n")
28972
0
SLANG_RAW("        }\n")
28973
0
SLANG_RAW("    case hlsl:\n")
28974
0
SLANG_RAW("        __intrinsic_asm \"max($0, $1)\";\n")
28975
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
28976
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
28977
0
SLANG_RAW("        ret.__mutMax(y);\n")
28978
0
SLANG_RAW("        return ret;\n")
28979
0
SLANG_RAW("    default:\n")
28980
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
28981
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
28982
0
SLANG_RAW("            ret[i] = max(x[i], y[i]);\n")
28983
0
SLANG_RAW("        return ret;\n")
28984
0
SLANG_RAW("    }\n")
28985
0
SLANG_RAW("}\n")
28986
0
SLANG_RAW("\n")
28987
0
SLANG_RAW("// [ForceInline]\n")
28988
0
SLANG_RAW("[require(cooperative_vector)]\n")
28989
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
28990
0
SLANG_RAW("CoopVec<T, N> clamp<T : __BuiltinIntegerType, let N : int>(CoopVec<T, N> x, CoopVec<T, N> minVal, CoopVec<T, N> maxVal)\n")
28991
0
SLANG_RAW("{\n")
28992
0
SLANG_RAW("    __target_switch\n")
28993
0
SLANG_RAW("    {\n")
28994
0
SLANG_RAW("    case spirv:\n")
28995
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
28996
0
SLANG_RAW("        {\n")
28997
0
SLANG_RAW("            return spirv_asm\n")
28998
0
SLANG_RAW("            {\n")
28999
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 SClamp $x $minVal $maxVal\n")
29000
0
SLANG_RAW("            };\n")
29001
0
SLANG_RAW("        }\n")
29002
0
SLANG_RAW("        else\n")
29003
0
SLANG_RAW("        {\n")
29004
0
SLANG_RAW("            return spirv_asm\n")
29005
0
SLANG_RAW("            {\n")
29006
0
SLANG_RAW("                result:$$CoopVec<T, N> = OpExtInst glsl450 UClamp $x $minVal $maxVal\n")
29007
0
SLANG_RAW("            };\n")
29008
0
SLANG_RAW("        }\n")
29009
0
SLANG_RAW("    case hlsl:\n")
29010
0
SLANG_RAW("        __intrinsic_asm \"clamp($0, $1, $2)\";\n")
29011
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29012
0
SLANG_RAW("        CoopVec<T, N> ret = x;\n")
29013
0
SLANG_RAW("        ret.__mutClamp(minVal, maxVal);\n")
29014
0
SLANG_RAW("        return ret;\n")
29015
0
SLANG_RAW("    default:\n")
29016
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29017
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29018
0
SLANG_RAW("            ret[i] = clamp(x[i], minVal[i], maxVal[i]);\n")
29019
0
SLANG_RAW("        return ret;\n")
29020
0
SLANG_RAW("    }\n")
29021
0
SLANG_RAW("}\n")
29022
0
SLANG_RAW("\n")
29023
0
SLANG_RAW("// [ForceInline]\n")
29024
0
SLANG_RAW("[require(cooperative_vector)]\n")
29025
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29026
0
SLANG_RAW("[require(optix_coopvec)]\n")
29027
0
SLANG_RAW("CoopVec<T, N> step<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> edge, CoopVec<T, N> x)\n")
29028
0
SLANG_RAW("{\n")
29029
0
SLANG_RAW("    __target_switch\n")
29030
0
SLANG_RAW("    {\n")
29031
0
SLANG_RAW("    case hlsl:\n")
29032
0
SLANG_RAW("        __intrinsic_asm \"step($0, $1)\";\n")
29033
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29034
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29035
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29036
0
SLANG_RAW("            ret[i] = step(edge[i], x[i]);\n")
29037
0
SLANG_RAW("        return ret;\n")
29038
0
SLANG_RAW("    case spirv:\n")
29039
0
SLANG_RAW("        return spirv_asm\n")
29040
0
SLANG_RAW("        {\n")
29041
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Step $edge $x;\n")
29042
0
SLANG_RAW("        };\n")
29043
0
SLANG_RAW("    case optix_coopvec:\n")
29044
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecStep($0, $1)\";\n")
29045
0
SLANG_RAW("    default:\n")
29046
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29047
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29048
0
SLANG_RAW("            ret[i] = step(edge[i], x[i]);\n")
29049
0
SLANG_RAW("        return ret;\n")
29050
0
SLANG_RAW("    }\n")
29051
0
SLANG_RAW("}\n")
29052
0
SLANG_RAW("\n")
29053
0
SLANG_RAW("// [ForceInline]\n")
29054
0
SLANG_RAW("[require(cooperative_vector)]\n")
29055
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29056
0
SLANG_RAW("CoopVec<T, N> exp<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x)\n")
29057
0
SLANG_RAW("{\n")
29058
0
SLANG_RAW("    __target_switch\n")
29059
0
SLANG_RAW("    {\n")
29060
0
SLANG_RAW("    case hlsl:\n")
29061
0
SLANG_RAW("        __intrinsic_asm \"exp($0)\";\n")
29062
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29063
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29064
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29065
0
SLANG_RAW("            ret[i] = exp(x[i]);\n")
29066
0
SLANG_RAW("        return ret;\n")
29067
0
SLANG_RAW("    case spirv:\n")
29068
0
SLANG_RAW("        return spirv_asm\n")
29069
0
SLANG_RAW("        {\n")
29070
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Exp $x;\n")
29071
0
SLANG_RAW("        };\n")
29072
0
SLANG_RAW("    default:\n")
29073
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29074
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29075
0
SLANG_RAW("            ret[i] = exp(x[i]);\n")
29076
0
SLANG_RAW("        return ret;\n")
29077
0
SLANG_RAW("    }\n")
29078
0
SLANG_RAW("}\n")
29079
0
SLANG_RAW("\n")
29080
0
SLANG_RAW("// [ForceInline]\n")
29081
0
SLANG_RAW("[require(cooperative_vector)]\n")
29082
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29083
0
SLANG_RAW("CoopVec<T, N> log<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x)\n")
29084
0
SLANG_RAW("{\n")
29085
0
SLANG_RAW("    __target_switch\n")
29086
0
SLANG_RAW("    {\n")
29087
0
SLANG_RAW("    case hlsl:\n")
29088
0
SLANG_RAW("        __intrinsic_asm \"log($0)\";\n")
29089
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29090
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29091
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29092
0
SLANG_RAW("            ret[i] = log(x[i]);\n")
29093
0
SLANG_RAW("        return ret;\n")
29094
0
SLANG_RAW("    case spirv:\n")
29095
0
SLANG_RAW("        return spirv_asm\n")
29096
0
SLANG_RAW("        {\n")
29097
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Log $x;\n")
29098
0
SLANG_RAW("        };\n")
29099
0
SLANG_RAW("    default:\n")
29100
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29101
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29102
0
SLANG_RAW("            ret[i] = log(x[i]);\n")
29103
0
SLANG_RAW("        return ret;\n")
29104
0
SLANG_RAW("    }\n")
29105
0
SLANG_RAW("}\n")
29106
0
SLANG_RAW("\n")
29107
0
SLANG_RAW("// [ForceInline]\n")
29108
0
SLANG_RAW("[require(cooperative_vector)]\n")
29109
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29110
0
SLANG_RAW("[require(optix_coopvec)]\n")
29111
0
SLANG_RAW("CoopVec<T, N> log2<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x)\n")
29112
0
SLANG_RAW("{\n")
29113
0
SLANG_RAW("    __target_switch\n")
29114
0
SLANG_RAW("    {\n")
29115
0
SLANG_RAW("    default:\n")
29116
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29117
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29118
0
SLANG_RAW("            ret[i] = log2(x[i]);\n")
29119
0
SLANG_RAW("        return ret;\n")
29120
0
SLANG_RAW("    case optix_coopvec:\n")
29121
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecLog2($0)\";\n")
29122
0
SLANG_RAW("    }\n")
29123
0
SLANG_RAW("}\n")
29124
0
SLANG_RAW("\n")
29125
0
SLANG_RAW("// [ForceInline]\n")
29126
0
SLANG_RAW("[require(cooperative_vector)]\n")
29127
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29128
0
SLANG_RAW("[require(optix_coopvec)]\n")
29129
0
SLANG_RAW("CoopVec<T, N> exp2<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x)\n")
29130
0
SLANG_RAW("{\n")
29131
0
SLANG_RAW("    __target_switch\n")
29132
0
SLANG_RAW("    {\n")
29133
0
SLANG_RAW("    default:\n")
29134
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29135
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29136
0
SLANG_RAW("            ret[i] = exp2(x[i]);\n")
29137
0
SLANG_RAW("        return ret;\n")
29138
0
SLANG_RAW("    case optix_coopvec:\n")
29139
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecExp2($0)\";\n")
29140
0
SLANG_RAW("    }\n")
29141
0
SLANG_RAW("}\n")
29142
0
SLANG_RAW("\n")
29143
0
SLANG_RAW("// [ForceInline]\n")
29144
0
SLANG_RAW("[require(cooperative_vector)]\n")
29145
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29146
0
SLANG_RAW("[require(optix_coopvec)]\n")
29147
0
SLANG_RAW("CoopVec<T, N> tanh<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> x)\n")
29148
0
SLANG_RAW("{\n")
29149
0
SLANG_RAW("    __target_switch\n")
29150
0
SLANG_RAW("    {\n")
29151
0
SLANG_RAW("    case hlsl:\n")
29152
0
SLANG_RAW("        __intrinsic_asm \"tanh($0)\";\n")
29153
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29154
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29155
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29156
0
SLANG_RAW("            ret[i] = tanh(x[i]);\n")
29157
0
SLANG_RAW("        return ret;\n")
29158
0
SLANG_RAW("    case spirv:\n")
29159
0
SLANG_RAW("        return spirv_asm\n")
29160
0
SLANG_RAW("        {\n")
29161
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Tanh $x;\n")
29162
0
SLANG_RAW("        };\n")
29163
0
SLANG_RAW("    case optix_coopvec:\n")
29164
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecTanh($0)\";\n")
29165
0
SLANG_RAW("    default:\n")
29166
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29167
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29168
0
SLANG_RAW("            ret[i] = tanh(x[i]);\n")
29169
0
SLANG_RAW("        return ret;\n")
29170
0
SLANG_RAW("    }\n")
29171
0
SLANG_RAW("}\n")
29172
0
SLANG_RAW("\n")
29173
0
SLANG_RAW("// [ForceInline]\n")
29174
0
SLANG_RAW("[require(cooperative_vector)]\n")
29175
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29176
0
SLANG_RAW("CoopVec<T, N> atan<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> yOverX)\n")
29177
0
SLANG_RAW("{\n")
29178
0
SLANG_RAW("    __target_switch\n")
29179
0
SLANG_RAW("    {\n")
29180
0
SLANG_RAW("    case hlsl:\n")
29181
0
SLANG_RAW("        __intrinsic_asm \"atan($0)\";\n")
29182
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29183
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29184
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29185
0
SLANG_RAW("            ret[i] = atan(yOverX[i]);\n")
29186
0
SLANG_RAW("        return ret;\n")
29187
0
SLANG_RAW("    case spirv:\n")
29188
0
SLANG_RAW("        return spirv_asm\n")
29189
0
SLANG_RAW("        {\n")
29190
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Atan $yOverX;\n")
29191
0
SLANG_RAW("        };\n")
29192
0
SLANG_RAW("    default:\n")
29193
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29194
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29195
0
SLANG_RAW("            ret[i] = atan(yOverX[i]);\n")
29196
0
SLANG_RAW("        return ret;\n")
29197
0
SLANG_RAW("    }\n")
29198
0
SLANG_RAW("}\n")
29199
0
SLANG_RAW("\n")
29200
0
SLANG_RAW("// [ForceInline]\n")
29201
0
SLANG_RAW("[require(cooperative_vector)]\n")
29202
0
SLANG_RAW("[require(cooperative_vector)]\n")
29203
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29204
0
SLANG_RAW("[require(optix_coopvec)]\n")
29205
0
SLANG_RAW("[require(GL_ARB_gpu_shader5)]\n")
29206
0
SLANG_RAW("CoopVec<T, N> fma<T : __BuiltinFloatingPointType, let N : int>(CoopVec<T, N> a, CoopVec<T, N> b, CoopVec<T, N> c)\n")
29207
0
SLANG_RAW("{\n")
29208
0
SLANG_RAW("    // TODO: Investigate, why does this fail if it's not inlined\n")
29209
0
SLANG_RAW("    // replacing fma with mad below also fixes things...\n")
29210
0
SLANG_RAW("    // dxc generated substantially different code\n")
29211
0
SLANG_RAW("    __target_switch\n")
29212
0
SLANG_RAW("    {\n")
29213
0
SLANG_RAW("    case hlsl:\n")
29214
0
SLANG_RAW("        __intrinsic_asm \"mad($0, $1, $2)\";\n")
29215
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29216
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29217
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29218
0
SLANG_RAW("            ret[i] = mad(a[i], b[i], c[i]);\n")
29219
0
SLANG_RAW("        return ret;\n")
29220
0
SLANG_RAW("    case spirv:\n")
29221
0
SLANG_RAW("        return spirv_asm\n")
29222
0
SLANG_RAW("        {\n")
29223
0
SLANG_RAW("            result:$$CoopVec<T, N> = OpExtInst glsl450 Fma $a $b $c;\n")
29224
0
SLANG_RAW("        };\n")
29225
0
SLANG_RAW("    case optix_coopvec:\n")
29226
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecFFMA($0, $1, $2)\";\n")
29227
0
SLANG_RAW("    default:\n")
29228
0
SLANG_RAW("        CoopVec<T, N> ret;\n")
29229
0
SLANG_RAW("        for(int i = 0; i < N; ++i)\n")
29230
0
SLANG_RAW("            ret[i] = mad(a[i], b[i], c[i]);\n")
29231
0
SLANG_RAW("        return ret;\n")
29232
0
SLANG_RAW("    }\n")
29233
0
SLANG_RAW("}\n")
29234
0
SLANG_RAW("\n")
29235
0
SLANG_RAW("// Buffers from which values of arbitrary type can be loaded from byte offsets\n")
29236
0
SLANG_RAW("interface IPhysicalBuffer\n")
29237
0
SLANG_RAW("{\n")
29238
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29239
0
SLANG_RAW("    T LoadByteOffset<T>(int offset);\n")
29240
0
SLANG_RAW("\n")
29241
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29242
0
SLANG_RAW("    Ptr<uint32_t[]> GetBufferPointer();\n")
29243
0
SLANG_RAW("}\n")
29244
0
SLANG_RAW("\n")
29245
0
SLANG_RAW("// Buffers to which values of arbitrary type can be stored at byte offsets\n")
29246
0
SLANG_RAW("interface IRWPhysicalBuffer : IPhysicalBuffer\n")
29247
0
SLANG_RAW("{\n")
29248
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29249
0
SLANG_RAW("    void StoreByteOffset<T>(int offset, T element);\n")
29250
0
SLANG_RAW("}\n")
29251
0
SLANG_RAW("\n")
29252
0
SLANG_RAW("extension ByteAddressBuffer : IPhysicalBuffer\n")
29253
0
SLANG_RAW("{\n")
29254
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29255
0
SLANG_RAW("    Ptr<uint32_t[]> GetBufferPointer()\n")
29256
0
SLANG_RAW("    {\n")
29257
0
SLANG_RAW("        return __getStructuredBufferPtr(__getEquivalentStructuredBuffer<uint32_t>(this));\n")
29258
0
SLANG_RAW("    }\n")
29259
0
SLANG_RAW("\n")
29260
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29261
0
SLANG_RAW("    T LoadByteOffset<T>(int offset)\n")
29262
0
SLANG_RAW("    {\n")
29263
0
SLANG_RAW("        return this.Load<T>(offset);\n")
29264
0
SLANG_RAW("    }\n")
29265
0
SLANG_RAW("}\n")
29266
0
SLANG_RAW("\n")
29267
0
SLANG_RAW("extension RWByteAddressBuffer : IPhysicalBuffer\n")
29268
0
SLANG_RAW("{\n")
29269
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29270
0
SLANG_RAW("    Ptr<uint32_t[]> GetBufferPointer()\n")
29271
0
SLANG_RAW("    {\n")
29272
0
SLANG_RAW("        return __getStructuredBufferPtr(__getEquivalentStructuredBuffer<uint32_t>(this));\n")
29273
0
SLANG_RAW("    }\n")
29274
0
SLANG_RAW("\n")
29275
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29276
0
SLANG_RAW("    T LoadByteOffset<T>(int offset)\n")
29277
0
SLANG_RAW("    {\n")
29278
0
SLANG_RAW("        return this.Load<T>(offset);\n")
29279
0
SLANG_RAW("    }\n")
29280
0
SLANG_RAW("}\n")
29281
0
SLANG_RAW("\n")
29282
0
SLANG_RAW("extension RWByteAddressBuffer : IRWPhysicalBuffer\n")
29283
0
SLANG_RAW("{\n")
29284
0
SLANG_RAW("    [__unsafeForceInlineEarly]\n")
29285
0
SLANG_RAW("    void StoreByteOffset<T>(int offset, T element)\n")
29286
0
SLANG_RAW("    {\n")
29287
0
SLANG_RAW("        return this.Store<T>(offset, element);\n")
29288
0
SLANG_RAW("    }\n")
29289
0
SLANG_RAW("}\n")
29290
0
SLANG_RAW("\n")
29291
0
SLANG_RAW("\n")
29292
0
SLANG_RAW("//\n")
29293
0
SLANG_RAW("// Convenience loading functions for cooperative vectors which infer the\n")
29294
0
SLANG_RAW("// element type for structured buffers and groupshared arrays (and ByteAddressBuffers for consistency\n")
29295
0
SLANG_RAW("//\n")
29296
0
SLANG_RAW("\n")
29297
0
SLANG_RAW("/// Load values from a byte-addressable buffer into a cooperative vector.\n")
29298
0
SLANG_RAW("/// @param buffer The source buffer to load data from.\n")
29299
0
SLANG_RAW("/// @param byteOffset16ByteAligned The byte offset from the start of the buffer. Must be 16-byte aligned.\n")
29300
0
SLANG_RAW("/// @return A new cooperative vector containing the loaded values.\n")
29301
0
SLANG_RAW("[ForceInline]\n")
29302
0
SLANG_RAW("[require(cooperative_vector)]\n")
29303
0
SLANG_RAW("CoopVec<T, N> coopVecLoad<let N : int, T : __BuiltinArithmeticType>(ByteAddressBuffer buffer, int32_t byteOffset16ByteAligned = 0)\n")
29304
0
SLANG_RAW("{\n")
29305
0
SLANG_RAW("    return CoopVec<T, N>.load(buffer, byteOffset16ByteAligned);\n")
29306
0
SLANG_RAW("}\n")
29307
0
SLANG_RAW("\n")
29308
0
SLANG_RAW("[ForceInline]\n")
29309
0
SLANG_RAW("[require(cooperative_vector)]\n")
29310
0
SLANG_RAW("CoopVec<T, N> coopVecLoad<let N : int, T : __BuiltinArithmeticType>(RWByteAddressBuffer buffer, int32_t byteOffset16ByteAligned = 0)\n")
29311
0
SLANG_RAW("{\n")
29312
0
SLANG_RAW("    return CoopVec<T, N>.load(buffer, byteOffset16ByteAligned);\n")
29313
0
SLANG_RAW("}\n")
29314
0
SLANG_RAW("\n")
29315
0
SLANG_RAW("[ForceInline]\n")
29316
0
SLANG_RAW("[require(cooperative_vector)]\n")
29317
0
SLANG_RAW("CoopVec<T, N> coopVecLoad<let N : int, T : __BuiltinArithmeticType>(StructuredBuffer<T> buffer, int32_t byteOffset16ByteAligned = 0)\n")
29318
0
SLANG_RAW("{\n")
29319
0
SLANG_RAW("    return CoopVec<T, N>.load(buffer, byteOffset16ByteAligned);\n")
29320
0
SLANG_RAW("}\n")
29321
0
SLANG_RAW("\n")
29322
0
SLANG_RAW("[ForceInline]\n")
29323
0
SLANG_RAW("[require(cooperative_vector)]\n")
29324
0
SLANG_RAW("CoopVec<T, N> coopVecLoad<let N : int, T : __BuiltinArithmeticType>(RWStructuredBuffer<T> buffer, int32_t byteOffset16ByteAligned = 0)\n")
29325
0
SLANG_RAW("{\n")
29326
0
SLANG_RAW("    return CoopVec<T, N>.load(buffer, byteOffset16ByteAligned);\n")
29327
0
SLANG_RAW("}\n")
29328
0
SLANG_RAW("\n")
29329
0
SLANG_RAW("[ForceInline]\n")
29330
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
29331
0
SLANG_RAW("CoopVec<T, N> coopVecLoad<let N : int, T : __BuiltinArithmeticType>(T* buffer, int32_t byteOffset16ByteAligned = 0)\n")
29332
0
SLANG_RAW("{\n")
29333
0
SLANG_RAW("    return CoopVec<T, N>.load(buffer, byteOffset16ByteAligned);\n")
29334
0
SLANG_RAW("}\n")
29335
0
SLANG_RAW("\n")
29336
0
SLANG_RAW("[ForceInline]\n")
29337
0
SLANG_RAW("[require(spirv, cooperative_vector, vk_mem_model)]\n")
29338
0
SLANG_RAW("CoopVec<T, N> coopVecLoadCoherent<let N : int, T : __BuiltinArithmeticType>(T* buffer, int32_t byteOffset16ByteAligned = 0, constexpr MemoryScope memoryScope = MemoryScope::Device)\n")
29339
0
SLANG_RAW("{\n")
29340
0
SLANG_RAW("    return CoopVec<T, N>.loadCoherent(buffer, byteOffset16ByteAligned, memoryScope);\n")
29341
0
SLANG_RAW("}\n")
29342
0
SLANG_RAW("\n")
29343
0
SLANG_RAW("// Groupshared\n")
29344
0
SLANG_RAW("[ForceInline]\n")
29345
0
SLANG_RAW("[require(cooperative_vector)]\n")
29346
0
SLANG_RAW("CoopVec<T, N> coopVecLoadGroupshared<let N : int, T : __BuiltinArithmeticType, let M : int>(__constref groupshared const T[M] data, int32_t byteOffset16ByteAligned = 0)\n")
29347
0
SLANG_RAW("{\n")
29348
0
SLANG_RAW("    return CoopVec<T, N>.load(data, byteOffset16ByteAligned);\n")
29349
0
SLANG_RAW("}\n")
29350
0
SLANG_RAW("\n")
29351
0
SLANG_RAW("//\n")
29352
0
SLANG_RAW("// Coop Vector matrix multiplication\n")
29353
0
SLANG_RAW("//\n")
29354
0
SLANG_RAW("\n")
29355
0
SLANG_RAW("\n")
29356
0
SLANG_RAW("/// Specifies the memory layout for matrices used in cooperative vector operations.\n")
29357
0
SLANG_RAW("/// @remarks This enum defines different matrix layout options that affect how matrix data is stored and accessed,\n")
29358
0
SLANG_RAW("/// including standard row-major and column-major layouts as well as specialized layouts optimized for specific operations.\n")
29359
0
SLANG_RAW("enum CoopVecMatrixLayout\n")
29360
0
SLANG_RAW("{\n")
29361
0
SLANG_RAW("    RowMajor,\n")
29362
0
SLANG_RAW("    ColumnMajor,\n")
29363
0
SLANG_RAW("    InferencingOptimal,\n")
29364
0
SLANG_RAW("    TrainingOptimal\n")
29365
0
SLANG_RAW("};\n")
29366
0
SLANG_RAW("\n")
29367
0
SLANG_RAW("/// Specifies how to interpret the values in a cooperative vector or matrix.\n")
29368
0
SLANG_RAW("/// @remarks This enum defines the various data types that can be used for elements in cooperative vectors and matrices,\n")
29369
0
SLANG_RAW("/// including packed formats where multiple values can be stored in a single element.\n")
29370
0
SLANG_RAW("enum CoopVecComponentType\n")
29371
0
SLANG_RAW("{\n")
29372
0
SLANG_RAW("    FloatE4M3,\n")
29373
0
SLANG_RAW("    FloatE5M2,\n")
29374
0
SLANG_RAW("    Float16,\n")
29375
0
SLANG_RAW("    Float32,\n")
29376
0
SLANG_RAW("    Float64,\n")
29377
0
SLANG_RAW("    SignedInt8,\n")
29378
0
SLANG_RAW("    SignedInt16,\n")
29379
0
SLANG_RAW("    SignedInt32,\n")
29380
0
SLANG_RAW("    SignedInt64,\n")
29381
0
SLANG_RAW("    SignedInt8Packed,\n")
29382
0
SLANG_RAW("    UnsignedInt8,\n")
29383
0
SLANG_RAW("    UnsignedInt16,\n")
29384
0
SLANG_RAW("    UnsignedInt32,\n")
29385
0
SLANG_RAW("    UnsignedInt64,\n")
29386
0
SLANG_RAW("    UnsignedInt8Packed\n")
29387
0
SLANG_RAW("};\n")
29388
0
SLANG_RAW("\n")
29389
0
SLANG_RAW("[ForceInline]\n")
29390
0
SLANG_RAW("int __inputInterpretationPackingFactor(CoopVecComponentType componentType)\n")
29391
0
SLANG_RAW("{\n")
29392
0
SLANG_RAW("    switch (componentType)\n")
29393
0
SLANG_RAW("    {\n")
29394
0
SLANG_RAW("    case CoopVecComponentType::SignedInt8Packed:\n")
29395
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt8Packed:\n")
29396
0
SLANG_RAW("        return 4;\n")
29397
0
SLANG_RAW("    }\n")
29398
0
SLANG_RAW("    return 1;\n")
29399
0
SLANG_RAW("}\n")
29400
0
SLANG_RAW("\n")
29401
0
SLANG_RAW("[ForceInline]\n")
29402
0
SLANG_RAW("bool __isPackedInputInterpretation(CoopVecComponentType componentType)\n")
29403
0
SLANG_RAW("{\n")
29404
0
SLANG_RAW("    return __inputInterpretationPackingFactor(componentType) != 1;\n")
29405
0
SLANG_RAW("}\n")
29406
0
SLANG_RAW("\n")
29407
0
SLANG_RAW("// TODO: We might consider some way of specifying these from our lookup tables\n")
29408
0
SLANG_RAW("[ForceInline]\n")
29409
0
SLANG_RAW("uint32_t __getSpvCoopVecMatrixLayout(CoopVecMatrixLayout layout)\n")
29410
0
SLANG_RAW("{\n")
29411
0
SLANG_RAW("    switch (layout)\n")
29412
0
SLANG_RAW("    {\n")
29413
0
SLANG_RAW("    case CoopVecMatrixLayout::RowMajor:\n")
29414
0
SLANG_RAW("        return 0;\n")
29415
0
SLANG_RAW("    case CoopVecMatrixLayout::ColumnMajor:\n")
29416
0
SLANG_RAW("        return 1;\n")
29417
0
SLANG_RAW("    case CoopVecMatrixLayout::InferencingOptimal:\n")
29418
0
SLANG_RAW("        return 2;\n")
29419
0
SLANG_RAW("    case CoopVecMatrixLayout::TrainingOptimal:\n")
29420
0
SLANG_RAW("        return 3;\n")
29421
0
SLANG_RAW("    default:\n")
29422
0
SLANG_RAW("        static_assert(false, \"unsupported layout value\");\n")
29423
0
SLANG_RAW("    }\n")
29424
0
SLANG_RAW("    return 0xffffffff;\n")
29425
0
SLANG_RAW("}\n")
29426
0
SLANG_RAW("\n")
29427
0
SLANG_RAW("[ForceInline]\n")
29428
0
SLANG_RAW("uint32_t __getHLSLCoopVecMatrixLayout(CoopVecMatrixLayout layout)\n")
29429
0
SLANG_RAW("{\n")
29430
0
SLANG_RAW("    switch (layout)\n")
29431
0
SLANG_RAW("    {\n")
29432
0
SLANG_RAW("    // TODO: Check these are the same\n")
29433
0
SLANG_RAW("    case CoopVecMatrixLayout::RowMajor:\n")
29434
0
SLANG_RAW("        return 0;\n")
29435
0
SLANG_RAW("    case CoopVecMatrixLayout::ColumnMajor:\n")
29436
0
SLANG_RAW("        return 1;\n")
29437
0
SLANG_RAW("    case CoopVecMatrixLayout::InferencingOptimal:\n")
29438
0
SLANG_RAW("        return 2;\n")
29439
0
SLANG_RAW("    case CoopVecMatrixLayout::TrainingOptimal:\n")
29440
0
SLANG_RAW("        return 3;\n")
29441
0
SLANG_RAW("    default:\n")
29442
0
SLANG_RAW("        static_assert(false, \"unsupported layout value\");\n")
29443
0
SLANG_RAW("    }\n")
29444
0
SLANG_RAW("    return 0xffffffff;\n")
29445
0
SLANG_RAW("}\n")
29446
0
SLANG_RAW("\n")
29447
0
SLANG_RAW("[ForceInline]\n")
29448
0
SLANG_RAW("uint32_t __getSpvCoopVecComponentType(CoopVecComponentType componentType)\n")
29449
0
SLANG_RAW("{\n")
29450
0
SLANG_RAW("    switch (componentType)\n")
29451
0
SLANG_RAW("    {\n")
29452
0
SLANG_RAW("    case CoopVecComponentType::Float16:\n")
29453
0
SLANG_RAW("        return 0;\n")
29454
0
SLANG_RAW("    case CoopVecComponentType::Float32:\n")
29455
0
SLANG_RAW("        return 1;\n")
29456
0
SLANG_RAW("    case CoopVecComponentType::Float64:\n")
29457
0
SLANG_RAW("        return 2;\n")
29458
0
SLANG_RAW("    case CoopVecComponentType::SignedInt8:\n")
29459
0
SLANG_RAW("        return 3;\n")
29460
0
SLANG_RAW("    case CoopVecComponentType::SignedInt16:\n")
29461
0
SLANG_RAW("        return 4;\n")
29462
0
SLANG_RAW("    case CoopVecComponentType::SignedInt32:\n")
29463
0
SLANG_RAW("        return 5;\n")
29464
0
SLANG_RAW("    case CoopVecComponentType::SignedInt8Packed:\n")
29465
0
SLANG_RAW("        return 1000491000;\n")
29466
0
SLANG_RAW("    case CoopVecComponentType::SignedInt64:\n")
29467
0
SLANG_RAW("        return 6;\n")
29468
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt8:\n")
29469
0
SLANG_RAW("        return 7;\n")
29470
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt16:\n")
29471
0
SLANG_RAW("        return 8;\n")
29472
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt32:\n")
29473
0
SLANG_RAW("        return 9;\n")
29474
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt8Packed:\n")
29475
0
SLANG_RAW("        return 1000491001;\n")
29476
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt64:\n")
29477
0
SLANG_RAW("        return 10;\n")
29478
0
SLANG_RAW("    case CoopVecComponentType::FloatE4M3:\n")
29479
0
SLANG_RAW("        return 1000491002;\n")
29480
0
SLANG_RAW("    case CoopVecComponentType::FloatE5M2:\n")
29481
0
SLANG_RAW("        return 1000491003;\n")
29482
0
SLANG_RAW("    default:\n")
29483
0
SLANG_RAW("        static_assert(false, \"unsupported componentType value\");\n")
29484
0
SLANG_RAW("    }\n")
29485
0
SLANG_RAW("    return 0xffffffff;\n")
29486
0
SLANG_RAW("}\n")
29487
0
SLANG_RAW("\n")
29488
0
SLANG_RAW("[ForceInline]\n")
29489
0
SLANG_RAW("uint32_t __getHLSLCoopVecComponentType(CoopVecComponentType componentType)\n")
29490
0
SLANG_RAW("{\n")
29491
0
SLANG_RAW("    __target_switch\n")
29492
0
SLANG_RAW("    {\n")
29493
0
SLANG_RAW("    case hlsl:\n")
29494
0
SLANG_RAW("        switch (componentType)\n")
29495
0
SLANG_RAW("        {\n")
29496
0
SLANG_RAW("        case CoopVecComponentType::SignedInt16:\n")
29497
0
SLANG_RAW("            return 2;\n")
29498
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt16:\n")
29499
0
SLANG_RAW("            return 3;\n")
29500
0
SLANG_RAW("        case CoopVecComponentType::SignedInt32:\n")
29501
0
SLANG_RAW("            return 4;\n")
29502
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt32:\n")
29503
0
SLANG_RAW("            return 5;\n")
29504
0
SLANG_RAW("        case CoopVecComponentType::SignedInt64:\n")
29505
0
SLANG_RAW("            return 6;\n")
29506
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt64:\n")
29507
0
SLANG_RAW("            return 7;\n")
29508
0
SLANG_RAW("        case CoopVecComponentType::Float16:\n")
29509
0
SLANG_RAW("            return 8;\n")
29510
0
SLANG_RAW("        case CoopVecComponentType::Float32:\n")
29511
0
SLANG_RAW("            return 9;\n")
29512
0
SLANG_RAW("        case CoopVecComponentType::Float64:\n")
29513
0
SLANG_RAW("            return 10;\n")
29514
0
SLANG_RAW("        case CoopVecComponentType::SignedInt8Packed:\n")
29515
0
SLANG_RAW("            return 17;\n")
29516
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt8Packed:\n")
29517
0
SLANG_RAW("            return 18;\n")
29518
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt8:\n")
29519
0
SLANG_RAW("            return 19;\n")
29520
0
SLANG_RAW("        case CoopVecComponentType::SignedInt8:\n")
29521
0
SLANG_RAW("            return 20;\n")
29522
0
SLANG_RAW("        case CoopVecComponentType::FloatE4M3:\n")
29523
0
SLANG_RAW("            return 21;\n")
29524
0
SLANG_RAW("        case CoopVecComponentType::FloatE5M2:\n")
29525
0
SLANG_RAW("            return 22;\n")
29526
0
SLANG_RAW("        default:\n")
29527
0
SLANG_RAW("            static_assert(false, \"unsupported componentType value\");\n")
29528
0
SLANG_RAW("        }\n")
29529
0
SLANG_RAW("        return 0; // ComponentType::Invalid\n")
29530
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
29531
0
SLANG_RAW("        switch (componentType)\n")
29532
0
SLANG_RAW("        {\n")
29533
0
SLANG_RAW("        case CoopVecComponentType::Float16:\n")
29534
0
SLANG_RAW("            return 0;\n")
29535
0
SLANG_RAW("        case CoopVecComponentType::Float32:\n")
29536
0
SLANG_RAW("            return 1;\n")
29537
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt8:\n")
29538
0
SLANG_RAW("            return 2;\n")
29539
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt16:\n")
29540
0
SLANG_RAW("            return 3;\n")
29541
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt32:\n")
29542
0
SLANG_RAW("            return 4;\n")
29543
0
SLANG_RAW("        case CoopVecComponentType::SignedInt8:\n")
29544
0
SLANG_RAW("            return 5;\n")
29545
0
SLANG_RAW("        case CoopVecComponentType::SignedInt16:\n")
29546
0
SLANG_RAW("            return 6;\n")
29547
0
SLANG_RAW("        case CoopVecComponentType::SignedInt32:\n")
29548
0
SLANG_RAW("            return 7;\n")
29549
0
SLANG_RAW("        case CoopVecComponentType::SignedInt8Packed:\n")
29550
0
SLANG_RAW("            return 8;\n")
29551
0
SLANG_RAW("        case CoopVecComponentType::UnsignedInt8Packed:\n")
29552
0
SLANG_RAW("            return 9;\n")
29553
0
SLANG_RAW("        case CoopVecComponentType::FloatE4M3:\n")
29554
0
SLANG_RAW("            return 10;\n")
29555
0
SLANG_RAW("        case CoopVecComponentType::FloatE5M2:\n")
29556
0
SLANG_RAW("            return 11;\n")
29557
0
SLANG_RAW("        default:\n")
29558
0
SLANG_RAW("            static_assert(false, \"unsupported componentType value\");\n")
29559
0
SLANG_RAW("        }\n")
29560
0
SLANG_RAW("        return 32;\n")
29561
0
SLANG_RAW("    }\n")
29562
0
SLANG_RAW("}\n")
29563
0
SLANG_RAW("\n")
29564
0
SLANG_RAW("[ForceInline]\n")
29565
0
SLANG_RAW("uint32_t __coopVecComponentTypeStride(CoopVecComponentType componentType)\n")
29566
0
SLANG_RAW("{\n")
29567
0
SLANG_RAW("    switch (componentType)\n")
29568
0
SLANG_RAW("    {\n")
29569
0
SLANG_RAW("    case CoopVecComponentType::Float16:\n")
29570
0
SLANG_RAW("        return 2;\n")
29571
0
SLANG_RAW("    case CoopVecComponentType::Float32:\n")
29572
0
SLANG_RAW("        return 4;\n")
29573
0
SLANG_RAW("    case CoopVecComponentType::Float64:\n")
29574
0
SLANG_RAW("        return 8;\n")
29575
0
SLANG_RAW("    case CoopVecComponentType::SignedInt8:\n")
29576
0
SLANG_RAW("        return 1;\n")
29577
0
SLANG_RAW("    case CoopVecComponentType::SignedInt16:\n")
29578
0
SLANG_RAW("        return 2;\n")
29579
0
SLANG_RAW("    case CoopVecComponentType::SignedInt32:\n")
29580
0
SLANG_RAW("        return 4;\n")
29581
0
SLANG_RAW("    case CoopVecComponentType::SignedInt8Packed:\n")
29582
0
SLANG_RAW("        return 4;\n")
29583
0
SLANG_RAW("    case CoopVecComponentType::SignedInt64:\n")
29584
0
SLANG_RAW("        return 8;\n")
29585
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt8:\n")
29586
0
SLANG_RAW("        return 1;\n")
29587
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt16:\n")
29588
0
SLANG_RAW("        return 2;\n")
29589
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt32:\n")
29590
0
SLANG_RAW("        return 4;\n")
29591
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt8Packed:\n")
29592
0
SLANG_RAW("        return 4;\n")
29593
0
SLANG_RAW("    case CoopVecComponentType::UnsignedInt64:\n")
29594
0
SLANG_RAW("        return 8;\n")
29595
0
SLANG_RAW("    default:\n")
29596
0
SLANG_RAW("        static_assert(false, \"unsupported componentType value\");\n")
29597
0
SLANG_RAW("    }\n")
29598
0
SLANG_RAW("    return 0xffffffff;\n")
29599
0
SLANG_RAW("}\n")
29600
0
SLANG_RAW("\n")
29601
29602
0
static const struct {
29603
0
    bool isRW;
29604
0
    char const* type;
29605
0
} kByteAddressBufferCases_[] =
29606
0
{
29607
0
    {true, "RWByteAddressBuffer"},
29608
0
    {false, "ByteAddressBuffer"},
29609
0
};
29610
0
for(auto buffer : kByteAddressBufferCases_) {
29611
0
SLANG_RAW("#line 26899 \"hlsl.meta.slang\"")
29612
0
SLANG_RAW("\n")
29613
0
SLANG_RAW("\n")
29614
0
SLANG_RAW("/// Multiply a cooperative vector with a matrix and return the result.\n")
29615
0
SLANG_RAW("/// @param input The input cooperative vector to multiply with the matrix.\n")
29616
0
SLANG_RAW("/// @param inputInterpretation Specifies how to interpret the values in the input vector (e.g. as packed values).\n")
29617
0
SLANG_RAW("/// @param k The number of columns in the matrix.\n")
29618
0
SLANG_RAW("/// @param matrix The matrix buffer to multiply with.\n")
29619
0
SLANG_RAW("/// @param matrixOffset Byte offset into the matrix buffer.\n")
29620
0
SLANG_RAW("/// @param matrixInterpretation Specifies how to interpret the values in the matrix.\n")
29621
0
SLANG_RAW("/// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
29622
0
SLANG_RAW("/// @param transpose Whether to transpose the matrix before multiplication.\n")
29623
0
SLANG_RAW("/// @param matrixStride The stride between matrix rows/columns in bytes.\n")
29624
0
SLANG_RAW("/// @return A new cooperative vector containing the result of the matrix multiplication.\n")
29625
0
SLANG_RAW("/// @remarks Unlike coopVecMatMul, this function supports packed input interpretations where multiple values\n")
29626
0
SLANG_RAW("/// can be packed into each element of the input vector. The k parameter specifies the actual number of\n")
29627
0
SLANG_RAW("/// values to use from the packed input.\n")
29628
0
SLANG_RAW("// TODO: Can we ForceInline for just hlsl? the other platforms don't really\n")
29629
0
SLANG_RAW("// need it\n")
29630
0
SLANG_RAW("[ForceInline]\n")
29631
0
SLANG_RAW("[require(cooperative_vector)]\n")
29632
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29633
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType>\n")
29634
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulPacked(\n")
29635
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
29636
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
29637
0
SLANG_RAW("    constexpr int k,\n")
29638
0
SLANG_RAW("    ")
29639
0
SLANG_SPLICE(buffer.type
29640
0
)
29641
0
SLANG_RAW(" matrix,\n")
29642
0
SLANG_RAW("    int32_t matrixOffset,\n")
29643
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
29644
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
29645
0
SLANG_RAW("    constexpr bool transpose,\n")
29646
0
SLANG_RAW("    constexpr uint matrixStride\n")
29647
0
SLANG_RAW(")\n")
29648
0
SLANG_RAW("{\n")
29649
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
29650
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
29651
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
29652
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
29653
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
29654
0
SLANG_RAW("\n")
29655
0
SLANG_RAW("    __target_switch\n")
29656
0
SLANG_RAW("    {\n")
29657
0
SLANG_RAW("    case spirv:\n")
29658
0
SLANG_RAW("        let m : int32_t = M;\n")
29659
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
29660
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
29661
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
29662
0
SLANG_RAW("        let matrixPtr = matrix.GetBufferPointer();\n")
29663
0
SLANG_RAW("\n")
29664
0
SLANG_RAW("        // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_cooperative_matrix.asciidoc#3x-cooperative-matrix-operands\n")
29665
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
29666
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
29667
0
SLANG_RAW("        {\n")
29668
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
29669
0
SLANG_RAW("        }\n")
29670
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
29671
0
SLANG_RAW("        {\n")
29672
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
29673
0
SLANG_RAW("        }\n")
29674
0
SLANG_RAW("        return spirv_asm\n")
29675
0
SLANG_RAW("        {\n")
29676
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulNV $input $inputInterpretationSpirv $matrixPtr $matrixOffset $matrixInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
29677
0
SLANG_RAW("        };\n")
29678
0
SLANG_RAW("\n")
29679
0
SLANG_RAW("    case hlsl:\n")
29680
0
SLANG_RAW("        var ret = CoopVec<T, M>(0);\n")
29681
0
SLANG_RAW("        let inputInterpretationHLSL = __getHLSLCoopVecComponentType(inputInterpretation);\n")
29682
0
SLANG_RAW("        let matrixInterpretationHLSL = __getHLSLCoopVecComponentType(matrixInterpretation);\n")
29683
0
SLANG_RAW("        let memoryLayoutHLSL = __getHLSLCoopVecMatrixLayout(memoryLayout);\n")
29684
0
SLANG_RAW("        ret.__mutMatMul(\n")
29685
0
SLANG_RAW("             input,\n")
29686
0
SLANG_RAW("             inputInterpretationHLSL,\n")
29687
0
SLANG_RAW("             matrix,\n")
29688
0
SLANG_RAW("             matrixOffset,\n")
29689
0
SLANG_RAW("             matrixInterpretationHLSL,\n")
29690
0
SLANG_RAW("             M,\n")
29691
0
SLANG_RAW("             k,\n")
29692
0
SLANG_RAW("             memoryLayoutHLSL,\n")
29693
0
SLANG_RAW("             transpose,\n")
29694
0
SLANG_RAW("             matrixStride\n")
29695
0
SLANG_RAW("        );\n")
29696
0
SLANG_RAW("        return ret;\n")
29697
0
SLANG_RAW("\n")
29698
0
SLANG_RAW("    default:\n")
29699
0
SLANG_RAW("        var result = CoopVec<T, M>(0);\n")
29700
0
SLANG_RAW("        var v = CoopVec<T, PackedK*4>();\n")
29701
0
SLANG_RAW("        // TODO: Insert language from the spec to describe this madness\n")
29702
0
SLANG_RAW("        if(k == PackedK)\n")
29703
0
SLANG_RAW("        {\n")
29704
0
SLANG_RAW("            for(int i = 0; i < k; ++i)\n")
29705
0
SLANG_RAW("                v[i] = __arithmetic_cast<T>(input[i]);\n")
29706
0
SLANG_RAW("        }\n")
29707
0
SLANG_RAW("        else\n")
29708
0
SLANG_RAW("        {\n")
29709
0
SLANG_RAW("            static_assert(k == PackedK*4, \"K must be 4 * PackedK for the non-spirv coopVecMatMulPacked backend\");\n")
29710
0
SLANG_RAW("            static_assert(inputInterpretation == CoopVecComponentType::SignedInt8Packed ||\n")
29711
0
SLANG_RAW("                          inputInterpretation == CoopVecComponentType::UnsignedInt8Packed,\n")
29712
0
SLANG_RAW("                          \"Packing is only supported for 4*int8 or 4*uint8 vectors\");\n")
29713
0
SLANG_RAW("            for(int i = 0; i < k; ++i)\n")
29714
0
SLANG_RAW("            {\n")
29715
0
SLANG_RAW("                let n = __arithmetic_cast<int32_t>(input[i/4]);\n")
29716
0
SLANG_RAW("                let s = int8_t(n >> ((i % 4) * 8) & 0xff);\n")
29717
0
SLANG_RAW("                v[i] = T(s);\n")
29718
0
SLANG_RAW("            }\n")
29719
0
SLANG_RAW("        }\n")
29720
0
SLANG_RAW("\n")
29721
0
SLANG_RAW("        for (int i = 0; i < M; ++i)\n")
29722
0
SLANG_RAW("        {\n")
29723
0
SLANG_RAW("            for (int j = 0; j < k; ++j)\n")
29724
0
SLANG_RAW("            {\n")
29725
0
SLANG_RAW("                int row = (transpose ^ memoryLayout == CoopVecMatrixLayout::ColumnMajor) ? j : i;\n")
29726
0
SLANG_RAW("                int col = (transpose ^ memoryLayout == CoopVecMatrixLayout::ColumnMajor) ? i : j;\n")
29727
0
SLANG_RAW("                int offset = matrixOffset + (row * matrixStride + col * __coopVecComponentTypeStride(matrixInterpretation));\n")
29728
0
SLANG_RAW("\n")
29729
0
SLANG_RAW("                switch (matrixInterpretation)\n")
29730
0
SLANG_RAW("                {\n")
29731
0
SLANG_RAW("                    case CoopVecComponentType::Float16:\n")
29732
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<half>(offset)) * v[j];\n")
29733
0
SLANG_RAW("                        break;\n")
29734
0
SLANG_RAW("                    case CoopVecComponentType::Float32:\n")
29735
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<float>(offset)) * v[j];\n")
29736
0
SLANG_RAW("                        break;\n")
29737
0
SLANG_RAW("                    case CoopVecComponentType::Float64:\n")
29738
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<double>(offset)) * v[j];\n")
29739
0
SLANG_RAW("                        break;\n")
29740
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt8:\n")
29741
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<int8_t>(offset)) * v[j];\n")
29742
0
SLANG_RAW("                        break;\n")
29743
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt16:\n")
29744
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<int16_t>(offset)) * v[j];\n")
29745
0
SLANG_RAW("                        break;\n")
29746
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt32:\n")
29747
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<int32_t>(offset)) * v[j];\n")
29748
0
SLANG_RAW("                        break;\n")
29749
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt64:\n")
29750
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<int64_t>(offset)) * v[j];\n")
29751
0
SLANG_RAW("                        break;\n")
29752
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt8Packed:\n")
29753
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<int8_t>(offset)) * v[j];\n")
29754
0
SLANG_RAW("                        break;\n")
29755
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt8:\n")
29756
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<uint8_t>(offset)) * v[j];\n")
29757
0
SLANG_RAW("                        break;\n")
29758
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt16:\n")
29759
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<uint16_t>(offset)) * v[j];\n")
29760
0
SLANG_RAW("                        break;\n")
29761
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt32:\n")
29762
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<uint32_t>(offset)) * v[j];\n")
29763
0
SLANG_RAW("                        break;\n")
29764
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt64:\n")
29765
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<uint64_t>(offset)) * v[j];\n")
29766
0
SLANG_RAW("                        break;\n")
29767
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt8Packed:\n")
29768
0
SLANG_RAW("                        result[i] += __arithmetic_cast<T>(matrix.LoadByteOffset<uint8_t>(offset)) * v[j];\n")
29769
0
SLANG_RAW("                        break;\n")
29770
0
SLANG_RAW("                }\n")
29771
0
SLANG_RAW("            }\n")
29772
0
SLANG_RAW("        }\n")
29773
0
SLANG_RAW("\n")
29774
0
SLANG_RAW("        return result;\n")
29775
0
SLANG_RAW("    }\n")
29776
0
SLANG_RAW("}\n")
29777
0
SLANG_RAW("\n")
29778
0
SLANG_RAW("/// Multiply a matrix with a cooperative vector. Given a M-row by K-col `matrix`, and a K-element column vector `input`, computes `matrix * input`, and\n")
29779
0
SLANG_RAW("/// returns a M-element vector.\n")
29780
0
SLANG_RAW("/// @param input The K-element input cooperative vector to multiply with the matrix.\n")
29781
0
SLANG_RAW("/// @param inputInterpretation Specifies how to interpret the values in the input vector (e.g. as 8-bit integers, 16-bit floats, etc).\n")
29782
0
SLANG_RAW("/// @param matrix The M-by-K matrix to multiply with the input vector.\n")
29783
0
SLANG_RAW("/// @param matrixOffset Byte offset into the matrix buffer.\n")
29784
0
SLANG_RAW("/// @param matrixInterpretation Specifies how to interpret the values in the matrix (e.g. as 8-bit integers, 16-bit floats, etc).\n")
29785
0
SLANG_RAW("/// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
29786
0
SLANG_RAW("/// @param transpose Whether to transpose the matrix before multiplication.\n")
29787
0
SLANG_RAW("/// @param matrixStride The stride in bytes between rows/columns of the matrix.\n")
29788
0
SLANG_RAW("/// @return A new cooperative vector containing the result of the matrix multiplication.\n")
29789
0
SLANG_RAW("/// @remarks Depending on target hardware, some combinations of `inputInterpretation`, `matrixInterpretation` and `memoryLayout` may not be supported.\n")
29790
0
SLANG_RAW("/// For example, CoopVecComponentType.Float32 is not widely supported. Developers should query device properties through the host graphics API to\n")
29791
0
SLANG_RAW("/// find out which interpretations are supported.\n")
29792
0
SLANG_RAW("///\n")
29793
0
SLANG_RAW("/// Transposing is not supported when `memoryLayout` is `RowMajor` or `ColumnMajor`, and `transpose` must be `false`.\n")
29794
0
SLANG_RAW("/// Not all component types support transposing.\n")
29795
0
SLANG_RAW("/// When `memoryLayout` is `InferencingOptimal` or `TrainingOptimal`, `matrixStride` is ignored.\n")
29796
0
SLANG_RAW("[ForceInline]\n")
29797
0
SLANG_RAW("[require(cooperative_vector)]\n")
29798
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29799
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType>\n")
29800
0
SLANG_RAW("CoopVec<T, M> coopVecMatMul(\n")
29801
0
SLANG_RAW("    CoopVec<U, K> input,\n")
29802
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
29803
0
SLANG_RAW("    ")
29804
0
SLANG_SPLICE(buffer.type
29805
0
)
29806
0
SLANG_RAW(" matrix,\n")
29807
0
SLANG_RAW("    int32_t matrixOffset,\n")
29808
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
29809
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
29810
0
SLANG_RAW("    constexpr bool transpose,\n")
29811
0
SLANG_RAW("    constexpr uint matrixStride\n")
29812
0
SLANG_RAW(")\n")
29813
0
SLANG_RAW("{\n")
29814
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
29815
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
29816
0
SLANG_RAW("    return coopVecMatMulPacked<\n")
29817
0
SLANG_RAW("        T, M, K, U>(\n")
29818
0
SLANG_RAW("        input,\n")
29819
0
SLANG_RAW("        inputInterpretation,\n")
29820
0
SLANG_RAW("        K,\n")
29821
0
SLANG_RAW("        matrix,\n")
29822
0
SLANG_RAW("        matrixOffset,\n")
29823
0
SLANG_RAW("        matrixInterpretation,\n")
29824
0
SLANG_RAW("        memoryLayout,\n")
29825
0
SLANG_RAW("        transpose,\n")
29826
0
SLANG_RAW("        matrixStride);\n")
29827
0
SLANG_RAW("}\n")
29828
0
SLANG_RAW("\n")
29829
0
SLANG_RAW("/// Multiply a matrix with a cooperative vector and add a bias vector to the result.\n")
29830
0
SLANG_RAW("/// Given a M-row by K-col `matrix`, a K-element column vector `input`, and a M-element vector `bias`, computes `matrix * input + bias`, and\n")
29831
0
SLANG_RAW("/// returns a M-element vector.\n")
29832
0
SLANG_RAW("/// @param input The input cooperative vector to multiply with the matrix.\n")
29833
0
SLANG_RAW("/// @param inputInterpretation Specifies how to interpret the values in the input vector (e.g. as packed values).\n")
29834
0
SLANG_RAW("/// @param k The number of columns in the matrix.\n")
29835
0
SLANG_RAW("/// @param matrix The matrix buffer to multiply with.\n")
29836
0
SLANG_RAW("/// @param matrixOffset Byte offset into the matrix buffer.\n")
29837
0
SLANG_RAW("/// @param matrixInterpretation Specifies how to interpret the values in the matrix.\n")
29838
0
SLANG_RAW("/// @param bias The bias buffer to add after multiplication.\n")
29839
0
SLANG_RAW("/// @param biasOffset Byte offset into the bias buffer.\n")
29840
0
SLANG_RAW("/// @param biasInterpretation Specifies how to interpret the values in the bias vector.\n")
29841
0
SLANG_RAW("/// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
29842
0
SLANG_RAW("/// @param transpose Whether to transpose the matrix before multiplication.\n")
29843
0
SLANG_RAW("/// @param matrixStride The stride between matrix rows/columns in bytes.\n")
29844
0
SLANG_RAW("/// @return A new cooperative vector containing the result of the matrix multiplication with added bias.\n")
29845
0
SLANG_RAW("/// @remarks Unlike coopVecMatMulAdd, this function supports packed input interpretations where multiple values\n")
29846
0
SLANG_RAW("/// can be packed into each element of the input vector. The k parameter specifies the actual number of\n")
29847
0
SLANG_RAW("/// values to use from the packed input.\n")
29848
0
SLANG_RAW("///\n")
29849
0
SLANG_RAW("/// Depending on target hardware, some combinations of `inputInterpretation`, `matrixInterpretation` and `memoryLayout` may not be supported.\n")
29850
0
SLANG_RAW("/// For example, CoopVecComponentType.Float32 is not widely supported. Developers should query device properties through the host graphics API to\n")
29851
0
SLANG_RAW("/// find out which interpretations are supported.\n")
29852
0
SLANG_RAW("///\n")
29853
0
SLANG_RAW("/// Transposing is not supported when `memoryLayout` is `RowMajor` or `ColumnMajor`, and `transpose` must be `false`.\n")
29854
0
SLANG_RAW("/// Not all component types support transposing.\n")
29855
0
SLANG_RAW("/// When `memoryLayout` is `InferencingOptimal` or `TrainingOptimal`, `matrixStride` is ignored.\n")
29856
0
SLANG_RAW("[ForceInline]\n")
29857
0
SLANG_RAW("[require(cooperative_vector)]\n")
29858
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
29859
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAddPacked<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType>(\n")
29860
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
29861
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
29862
0
SLANG_RAW("    constexpr int k,\n")
29863
0
SLANG_RAW("    ")
29864
0
SLANG_SPLICE(buffer.type
29865
0
)
29866
0
SLANG_RAW(" matrix,\n")
29867
0
SLANG_RAW("    int32_t matrixOffset,\n")
29868
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
29869
0
SLANG_RAW("    ")
29870
0
SLANG_SPLICE(buffer.type
29871
0
)
29872
0
SLANG_RAW(" bias,\n")
29873
0
SLANG_RAW("    int32_t biasOffset,\n")
29874
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
29875
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
29876
0
SLANG_RAW("    constexpr bool transpose,\n")
29877
0
SLANG_RAW("    constexpr uint matrixStride\n")
29878
0
SLANG_RAW(")\n")
29879
0
SLANG_RAW("{\n")
29880
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
29881
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
29882
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
29883
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
29884
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
29885
0
SLANG_RAW("\n")
29886
0
SLANG_RAW("    __target_switch\n")
29887
0
SLANG_RAW("    {\n")
29888
0
SLANG_RAW("    case spirv:\n")
29889
0
SLANG_RAW("        let m : int32_t = M;\n")
29890
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
29891
0
SLANG_RAW("        let biasInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(biasInterpretation);\n")
29892
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
29893
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
29894
0
SLANG_RAW("        let matrixPtr = matrix.GetBufferPointer();\n")
29895
0
SLANG_RAW("        let biasPtr = bias.GetBufferPointer();\n")
29896
0
SLANG_RAW("\n")
29897
0
SLANG_RAW("        // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_cooperative_matrix.asciidoc#3x-cooperative-matrix-operands\n")
29898
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
29899
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
29900
0
SLANG_RAW("        {\n")
29901
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
29902
0
SLANG_RAW("        }\n")
29903
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
29904
0
SLANG_RAW("        {\n")
29905
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
29906
0
SLANG_RAW("        }\n")
29907
0
SLANG_RAW("        return spirv_asm\n")
29908
0
SLANG_RAW("        {\n")
29909
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulAddNV $input $inputInterpretationSpirv $matrixPtr $matrixOffset $matrixInterpretationSpirv $biasPtr $biasOffset $biasInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
29910
0
SLANG_RAW("        };\n")
29911
0
SLANG_RAW("\n")
29912
0
SLANG_RAW("    case hlsl:\n")
29913
0
SLANG_RAW("        var ret = CoopVec<T, M>(0);\n")
29914
0
SLANG_RAW("        let inputInterpretationHLSL = __getHLSLCoopVecComponentType(inputInterpretation);\n")
29915
0
SLANG_RAW("        let matrixInterpretationHLSL = __getHLSLCoopVecComponentType(matrixInterpretation);\n")
29916
0
SLANG_RAW("        let biasInterpretationHLSL = __getHLSLCoopVecComponentType(biasInterpretation);\n")
29917
0
SLANG_RAW("        let memoryLayoutHLSL = __getHLSLCoopVecMatrixLayout(memoryLayout);\n")
29918
0
SLANG_RAW("        ret.__mutMatMulAdd(\n")
29919
0
SLANG_RAW("             input,\n")
29920
0
SLANG_RAW("             inputInterpretationHLSL,\n")
29921
0
SLANG_RAW("             matrix,\n")
29922
0
SLANG_RAW("             matrixOffset,\n")
29923
0
SLANG_RAW("             matrixInterpretationHLSL,\n")
29924
0
SLANG_RAW("             bias,\n")
29925
0
SLANG_RAW("             biasOffset,\n")
29926
0
SLANG_RAW("             biasInterpretationHLSL,\n")
29927
0
SLANG_RAW("             M,\n")
29928
0
SLANG_RAW("             k,\n")
29929
0
SLANG_RAW("             memoryLayoutHLSL,\n")
29930
0
SLANG_RAW("             transpose,\n")
29931
0
SLANG_RAW("             matrixStride\n")
29932
0
SLANG_RAW("        );\n")
29933
0
SLANG_RAW("        return ret;\n")
29934
0
SLANG_RAW("\n")
29935
0
SLANG_RAW("    default:\n")
29936
0
SLANG_RAW("        var result = coopVecMatMulPacked<T, M, PackedK, U>(\n")
29937
0
SLANG_RAW("            input,\n")
29938
0
SLANG_RAW("            inputInterpretation,\n")
29939
0
SLANG_RAW("            k,\n")
29940
0
SLANG_RAW("            matrix,\n")
29941
0
SLANG_RAW("            matrixOffset,\n")
29942
0
SLANG_RAW("            matrixInterpretation,\n")
29943
0
SLANG_RAW("            memoryLayout,\n")
29944
0
SLANG_RAW("            transpose,\n")
29945
0
SLANG_RAW("            matrixStride);\n")
29946
0
SLANG_RAW("\n")
29947
0
SLANG_RAW("        for (int i = 0; i < M; ++i)\n")
29948
0
SLANG_RAW("        {\n")
29949
0
SLANG_RAW("            int b = biasOffset + i * __coopVecComponentTypeStride(biasInterpretation);\n")
29950
0
SLANG_RAW("            switch (biasInterpretation)\n")
29951
0
SLANG_RAW("            {\n")
29952
0
SLANG_RAW("                case CoopVecComponentType::Float16:\n")
29953
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<half>(b));\n")
29954
0
SLANG_RAW("                    break;\n")
29955
0
SLANG_RAW("                case CoopVecComponentType::Float32:\n")
29956
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<float>(b));\n")
29957
0
SLANG_RAW("                    break;\n")
29958
0
SLANG_RAW("                case CoopVecComponentType::Float64:\n")
29959
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<double>(b));\n")
29960
0
SLANG_RAW("                    break;\n")
29961
0
SLANG_RAW("                case CoopVecComponentType::SignedInt8:\n")
29962
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<int8_t>(b));\n")
29963
0
SLANG_RAW("                    break;\n")
29964
0
SLANG_RAW("                case CoopVecComponentType::SignedInt16:\n")
29965
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<int16_t>(b));\n")
29966
0
SLANG_RAW("                    break;\n")
29967
0
SLANG_RAW("                case CoopVecComponentType::SignedInt32:\n")
29968
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<int32_t>(b));\n")
29969
0
SLANG_RAW("                    break;\n")
29970
0
SLANG_RAW("                case CoopVecComponentType::SignedInt64:\n")
29971
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<int64_t>(b));\n")
29972
0
SLANG_RAW("                    break;\n")
29973
0
SLANG_RAW("                case CoopVecComponentType::SignedInt8Packed:\n")
29974
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<int8_t>(b));\n")
29975
0
SLANG_RAW("                    break;\n")
29976
0
SLANG_RAW("                case CoopVecComponentType::UnsignedInt8:\n")
29977
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<uint8_t>(b));\n")
29978
0
SLANG_RAW("                    break;\n")
29979
0
SLANG_RAW("                case CoopVecComponentType::UnsignedInt16:\n")
29980
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<uint16_t>(b));\n")
29981
0
SLANG_RAW("                    break;\n")
29982
0
SLANG_RAW("                case CoopVecComponentType::UnsignedInt32:\n")
29983
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<uint32_t>(b));\n")
29984
0
SLANG_RAW("                    break;\n")
29985
0
SLANG_RAW("                case CoopVecComponentType::UnsignedInt64:\n")
29986
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<uint64_t>(b));\n")
29987
0
SLANG_RAW("                    break;\n")
29988
0
SLANG_RAW("                case CoopVecComponentType::UnsignedInt8Packed:\n")
29989
0
SLANG_RAW("                    result[i] += __arithmetic_cast<T>(bias.LoadByteOffset<uint8_t>(b));\n")
29990
0
SLANG_RAW("                    break;\n")
29991
0
SLANG_RAW("            }\n")
29992
0
SLANG_RAW("        }\n")
29993
0
SLANG_RAW("\n")
29994
0
SLANG_RAW("        return result;\n")
29995
0
SLANG_RAW("    }\n")
29996
0
SLANG_RAW("}\n")
29997
0
SLANG_RAW("\n")
29998
0
SLANG_RAW("/// Multiply a matrix with a cooperative vector and add a bias vector.\n")
29999
0
SLANG_RAW("/// Given a M-row by K-col `matrix`, a K-element column vector `input`, and a M-element vector `bias`, computes `matrix * input + bias`, and\n")
30000
0
SLANG_RAW("/// returns a M-element vector.\n")
30001
0
SLANG_RAW("/// @param input The input cooperative vector to multiply with the matrix.\n")
30002
0
SLANG_RAW("/// @param inputInterpretation Specifies how to interpret the values in the input vector.\n")
30003
0
SLANG_RAW("/// @param matrix The matrix buffer to multiply with.\n")
30004
0
SLANG_RAW("/// @param matrixOffset Byte offset into the matrix buffer.\n")
30005
0
SLANG_RAW("/// @param matrixInterpretation Specifies how to interpret the values in the matrix.\n")
30006
0
SLANG_RAW("/// @param bias The bias buffer to add after multiplication.\n")
30007
0
SLANG_RAW("/// @param biasOffset Byte offset into the bias buffer.\n")
30008
0
SLANG_RAW("/// @param biasInterpretation Specifies how to interpret the values in the bias vector.\n")
30009
0
SLANG_RAW("/// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
30010
0
SLANG_RAW("/// @param transpose Whether to transpose the matrix before multiplication.\n")
30011
0
SLANG_RAW("/// @param matrixStride The stride between matrix rows/columns in bytes.\n")
30012
0
SLANG_RAW("/// @return A new cooperative vector containing the result of the matrix multiplication plus bias.\n")
30013
0
SLANG_RAW("/// @remarks Depending on target hardware, some combinations of `inputInterpretation`, `matrixInterpretation` and `memoryLayout` may not be supported.\n")
30014
0
SLANG_RAW("/// For example, CoopVecComponentType.Float32 is not widely supported. Developers should query device properties through the host graphics API to\n")
30015
0
SLANG_RAW("/// find out which interpretations are supported.\n")
30016
0
SLANG_RAW("///\n")
30017
0
SLANG_RAW("/// Transposing is not supported when `memoryLayout` is `RowMajor` or `ColumnMajor`, and `transpose` must be `false`.\n")
30018
0
SLANG_RAW("/// Not all component types support transposing.\n")
30019
0
SLANG_RAW("/// When `memoryLayout` is `InferencingOptimal` or `TrainingOptimal`, `matrixStride` is ignored.\n")
30020
0
SLANG_RAW("[ForceInline]\n")
30021
0
SLANG_RAW("[require(cooperative_vector)]\n")
30022
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
30023
0
SLANG_RAW("[require(optix_coopvec)]\n")
30024
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType>\n")
30025
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAdd(\n")
30026
0
SLANG_RAW("    CoopVec<U, K> input,\n")
30027
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30028
0
SLANG_RAW("    ")
30029
0
SLANG_SPLICE(buffer.type
30030
0
)
30031
0
SLANG_RAW(" matrix,\n")
30032
0
SLANG_RAW("    int32_t matrixOffset,\n")
30033
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30034
0
SLANG_RAW("    ")
30035
0
SLANG_SPLICE(buffer.type
30036
0
)
30037
0
SLANG_RAW(" bias,\n")
30038
0
SLANG_RAW("    int32_t biasOffset,\n")
30039
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
30040
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30041
0
SLANG_RAW("    constexpr bool transpose,\n")
30042
0
SLANG_RAW("    constexpr uint matrixStride\n")
30043
0
SLANG_RAW(")\n")
30044
0
SLANG_RAW("{\n")
30045
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30046
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
30047
0
SLANG_RAW("    return coopVecMatMulAddPacked<\n")
30048
0
SLANG_RAW("        T, M, K, U>(\n")
30049
0
SLANG_RAW("        input,\n")
30050
0
SLANG_RAW("        inputInterpretation,\n")
30051
0
SLANG_RAW("        K,\n")
30052
0
SLANG_RAW("        matrix,\n")
30053
0
SLANG_RAW("        matrixOffset,\n")
30054
0
SLANG_RAW("        matrixInterpretation,\n")
30055
0
SLANG_RAW("        bias,\n")
30056
0
SLANG_RAW("        biasOffset,\n")
30057
0
SLANG_RAW("        biasInterpretation,\n")
30058
0
SLANG_RAW("        memoryLayout,\n")
30059
0
SLANG_RAW("        transpose,\n")
30060
0
SLANG_RAW("        matrixStride);\n")
30061
0
SLANG_RAW("}\n")
30062
0
SLANG_RAW("\n")
30063
0
SLANG_RAW("//\n")
30064
0
SLANG_RAW("// Coop Vector accumulation\n")
30065
0
SLANG_RAW("//\n")
30066
0
SLANG_RAW("\n")
30067
30068
0
if(buffer.isRW)
30069
0
{
30070
0
SLANG_RAW("#line 27339 \"hlsl.meta.slang\"")
30071
0
SLANG_RAW("\n")
30072
0
SLANG_RAW("/// Atomically accumulates the outer product of two cooperative vectors into a matrix. Given an M-element vector `a`, and an N-element vector `b`,\n")
30073
0
SLANG_RAW("/// compute the outer product of `a` and `b`, forming a M-row by N-col matrix. The elements in the matrix is then atomically accumulated\n")
30074
0
SLANG_RAW("/// to memory location represented by `matrix`.\n")
30075
0
SLANG_RAW("/// @param a The first cooperative vector.\n")
30076
0
SLANG_RAW("/// @param b The second cooperative vector.\n")
30077
0
SLANG_RAW("/// @param matrix The matrix buffer to accumulate the result into.\n")
30078
0
SLANG_RAW("/// @param matrixOffset Byte offset into the matrix buffer.\n")
30079
0
SLANG_RAW("/// @param matrixStride The stride between matrix rows/columns in bytes.\n")
30080
0
SLANG_RAW("/// @param memoryLayout Specifies the memory layout of the matrix (row-major or column-major).\n")
30081
0
SLANG_RAW("/// @param matrixInterpretation Specifies how to interpret the values in the matrix.\n")
30082
0
SLANG_RAW("/// @remarks On current hardware, `memoryLayout` must be `TrainingOptimal`.\n")
30083
0
SLANG_RAW("///\n")
30084
0
SLANG_RAW("/// When `memoryLayout` is `RowMajor`, this function is equivalent to:\n")
30085
0
SLANG_RAW("///\n")
30086
0
SLANG_RAW("/// ```\n")
30087
0
SLANG_RAW("/// uint8_t* matrixPtr = matrix + matrixOffset;\n")
30088
0
SLANG_RAW("/// for (int i = 0; i < M; i++)\n")
30089
0
SLANG_RAW("/// {\n")
30090
0
SLANG_RAW("///    for (int j = 0; j < N; j++)\n")
30091
0
SLANG_RAW("///    {\n")
30092
0
SLANG_RAW("///        let elem = a[i] * b[j];\n")
30093
0
SLANG_RAW("///        atomicAdd(matrixPtr + i * matrixStride + j * sizeof(T), elem);\n")
30094
0
SLANG_RAW("///    }\n")
30095
0
SLANG_RAW("/// }\n")
30096
0
SLANG_RAW("/// ```\n")
30097
0
SLANG_RAW("[require(cooperative_vector)]\n")
30098
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
30099
0
SLANG_RAW("[require(optix_coopvec)]\n")
30100
0
SLANG_RAW("void coopVecOuterProductAccumulate<T : __BuiltinArithmeticType, let M : int, let N : int>(\n")
30101
0
SLANG_RAW("    CoopVec<T, M> a,\n")
30102
0
SLANG_RAW("    CoopVec<T, N> b,\n")
30103
0
SLANG_RAW("    ")
30104
0
SLANG_SPLICE(buffer.type
30105
0
)
30106
0
SLANG_RAW(" matrix,\n")
30107
0
SLANG_RAW("    int32_t matrixOffset,\n")
30108
0
SLANG_RAW("    constexpr uint matrixStride,\n")
30109
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30110
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30111
0
SLANG_RAW(")\n")
30112
0
SLANG_RAW("{\n")
30113
0
SLANG_RAW("    __target_switch\n")
30114
0
SLANG_RAW("    {\n")
30115
0
SLANG_RAW("    case hlsl:\n")
30116
0
SLANG_RAW("        uint matrixInterpretationHLSL = __getHLSLCoopVecComponentType(matrixInterpretation);\n")
30117
0
SLANG_RAW("        uint memoryLayoutHLSL = __getHLSLCoopVecMatrixLayout(memoryLayout);\n")
30118
0
SLANG_RAW("        return a.__OuterProductAccumulate(b, matrix, matrixOffset, matrixStride, memoryLayoutHLSL, matrixInterpretationHLSL);\n")
30119
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
30120
0
SLANG_RAW("        __intrinsic_asm \"$0.OuterProductAccumulate($1, $2, $3, $4, $5, $6)\";\n")
30121
0
SLANG_RAW("    case spirv:\n")
30122
0
SLANG_RAW("        let matrixInterpretationSpirv : int = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30123
0
SLANG_RAW("        let memoryLayoutSpirv : int = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30124
0
SLANG_RAW("        let matrixPtr = matrix.GetBufferPointer();\n")
30125
0
SLANG_RAW("        spirv_asm\n")
30126
0
SLANG_RAW("        {\n")
30127
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30128
0
SLANG_RAW("            OpCooperativeVectorOuterProductAccumulateNV $matrixPtr $matrixOffset $a $b $memoryLayoutSpirv $matrixInterpretationSpirv $matrixStride;\n")
30129
0
SLANG_RAW("        };\n")
30130
0
SLANG_RAW("    case optix_coopvec:\n")
30131
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecOuterProductAccumulate($0, $1, (CUdeviceptr)(&$2), $3, $4)\";\n")
30132
0
SLANG_RAW("    default:\n")
30133
0
SLANG_RAW("        for (int i = 0; i < M; ++i)\n")
30134
0
SLANG_RAW("        {\n")
30135
0
SLANG_RAW("            for (int j = 0; j < N; ++j)\n")
30136
0
SLANG_RAW("            {\n")
30137
0
SLANG_RAW("                T product = a[i] * b[j];\n")
30138
0
SLANG_RAW("                int row = (memoryLayout == CoopVecMatrixLayout::ColumnMajor) ? j : i;\n")
30139
0
SLANG_RAW("                int col = (memoryLayout == CoopVecMatrixLayout::ColumnMajor) ? i : j;\n")
30140
0
SLANG_RAW("                int offset = matrixOffset + (row * matrixStride + col * __coopVecComponentTypeStride(matrixInterpretation));\n")
30141
0
SLANG_RAW("\n")
30142
0
SLANG_RAW("                switch (matrixInterpretation)\n")
30143
0
SLANG_RAW("                {\n")
30144
0
SLANG_RAW("                    case CoopVecComponentType::Float16:\n")
30145
0
SLANG_RAW("                        matrix.StoreByteOffset<half>(offset, matrix.LoadByteOffset<half>(offset) + __arithmetic_cast<half>(product));\n")
30146
0
SLANG_RAW("                        break;\n")
30147
0
SLANG_RAW("                    case CoopVecComponentType::Float32:\n")
30148
0
SLANG_RAW("                        matrix.StoreByteOffset<float>(offset, matrix.LoadByteOffset<float>(offset) + __arithmetic_cast<float>(product));\n")
30149
0
SLANG_RAW("                        break;\n")
30150
0
SLANG_RAW("                    case CoopVecComponentType::Float64:\n")
30151
0
SLANG_RAW("                        matrix.StoreByteOffset<double>(offset, matrix.LoadByteOffset<double>(offset) + __arithmetic_cast<double>(product));\n")
30152
0
SLANG_RAW("                        break;\n")
30153
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt8:\n")
30154
0
SLANG_RAW("                        matrix.StoreByteOffset<int8_t>(offset, matrix.LoadByteOffset<int8_t>(offset) + __arithmetic_cast<int8_t>(product));\n")
30155
0
SLANG_RAW("                        break;\n")
30156
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt16:\n")
30157
0
SLANG_RAW("                        matrix.StoreByteOffset<int16_t>(offset, matrix.LoadByteOffset<int16_t>(offset) + __arithmetic_cast<int16_t>(product));\n")
30158
0
SLANG_RAW("                        break;\n")
30159
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt32:\n")
30160
0
SLANG_RAW("                        matrix.StoreByteOffset<int32_t>(offset, matrix.LoadByteOffset<int32_t>(offset) + __arithmetic_cast<int32_t>(product));\n")
30161
0
SLANG_RAW("                        break;\n")
30162
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt64:\n")
30163
0
SLANG_RAW("                        matrix.StoreByteOffset<int64_t>(offset, matrix.LoadByteOffset<int64_t>(offset) + __arithmetic_cast<int64_t>(product));\n")
30164
0
SLANG_RAW("                        break;\n")
30165
0
SLANG_RAW("                    case CoopVecComponentType::SignedInt8Packed:\n")
30166
0
SLANG_RAW("                        matrix.StoreByteOffset<int8_t>(offset, matrix.LoadByteOffset<int8_t>(offset) + __arithmetic_cast<int8_t>(product));\n")
30167
0
SLANG_RAW("                        break;\n")
30168
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt8:\n")
30169
0
SLANG_RAW("                        matrix.StoreByteOffset<uint8_t>(offset, matrix.LoadByteOffset<uint8_t>(offset) + __arithmetic_cast<uint8_t>(product));\n")
30170
0
SLANG_RAW("                        break;\n")
30171
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt16:\n")
30172
0
SLANG_RAW("                        matrix.StoreByteOffset<uint16_t>(offset, matrix.LoadByteOffset<uint16_t>(offset) + __arithmetic_cast<uint16_t>(product));\n")
30173
0
SLANG_RAW("                        break;\n")
30174
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt32:\n")
30175
0
SLANG_RAW("                        matrix.StoreByteOffset<uint32_t>(offset, matrix.LoadByteOffset<uint32_t>(offset) + __arithmetic_cast<uint32_t>(product));\n")
30176
0
SLANG_RAW("                        break;\n")
30177
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt64:\n")
30178
0
SLANG_RAW("                        matrix.StoreByteOffset<uint64_t>(offset, matrix.LoadByteOffset<uint64_t>(offset) + __arithmetic_cast<uint64_t>(product));\n")
30179
0
SLANG_RAW("                        break;\n")
30180
0
SLANG_RAW("                    case CoopVecComponentType::UnsignedInt8Packed:\n")
30181
0
SLANG_RAW("                        matrix.StoreByteOffset<uint8_t>(offset, matrix.LoadByteOffset<uint8_t>(offset) + __arithmetic_cast<uint8_t>(product));\n")
30182
0
SLANG_RAW("                        break;\n")
30183
0
SLANG_RAW("                }\n")
30184
0
SLANG_RAW("            }\n")
30185
0
SLANG_RAW("        }\n")
30186
0
SLANG_RAW("    }\n")
30187
0
SLANG_RAW("}\n")
30188
0
SLANG_RAW("\n")
30189
0
SLANG_RAW("/// Atomically accumulates the elements a cooperative vector into a buffer at the specified offset.\n")
30190
0
SLANG_RAW("/// @param v The cooperative vector to sum.\n")
30191
0
SLANG_RAW("/// @param buffer The buffer to accumulate the sum into.\n")
30192
0
SLANG_RAW("/// @param offset Byte offset into the buffer.\n")
30193
0
SLANG_RAW("/// @remarks This function is equivalent to:\n")
30194
0
SLANG_RAW("/// ```\n")
30195
0
SLANG_RAW("/// for (int i = 0; i < N; i++)\n")
30196
0
SLANG_RAW("///     atomicAdd(dest[i], v[i]);\n")
30197
0
SLANG_RAW("/// ```\n")
30198
0
SLANG_RAW("[require(cooperative_vector)]\n")
30199
0
SLANG_RAW("[require(hlsl_coopvec_poc)]\n")
30200
0
SLANG_RAW("[require(optix_coopvec)]\n")
30201
0
SLANG_RAW("void coopVecReduceSumAccumulate<T : __BuiltinArithmeticType, let N : int>(\n")
30202
0
SLANG_RAW("    CoopVec<T, N> v,\n")
30203
0
SLANG_RAW("    ")
30204
0
SLANG_SPLICE(buffer.type
30205
0
)
30206
0
SLANG_RAW(" buffer,\n")
30207
0
SLANG_RAW("    int32_t offset\n")
30208
0
SLANG_RAW(")\n")
30209
0
SLANG_RAW("{\n")
30210
0
SLANG_RAW("    __target_switch\n")
30211
0
SLANG_RAW("    {\n")
30212
0
SLANG_RAW("    case hlsl:\n")
30213
0
SLANG_RAW("        __intrinsic_asm \"__builtin_VectorAccumulate($0, $1, $2)\";\n")
30214
0
SLANG_RAW("    case hlsl_coopvec_poc:\n")
30215
0
SLANG_RAW("        __intrinsic_asm \"$0.ReduceSumAccumulate($1, $2)\";\n")
30216
0
SLANG_RAW("    case spirv:\n")
30217
0
SLANG_RAW("        let bufferPtr = buffer.GetBufferPointer();\n")
30218
0
SLANG_RAW("        spirv_asm\n")
30219
0
SLANG_RAW("        {\n")
30220
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30221
0
SLANG_RAW("            OpCooperativeVectorReduceSumAccumulateNV $bufferPtr $offset $v;\n")
30222
0
SLANG_RAW("        };\n")
30223
0
SLANG_RAW("    case optix_coopvec:\n")
30224
0
SLANG_RAW("        __intrinsic_asm \"optixCoopVecReduceSumAccumulate($0, (CUdeviceptr)(&$1), $2)\";\n")
30225
0
SLANG_RAW("    default:\n")
30226
0
SLANG_RAW("        for (int i = 0; i < N; ++i)\n")
30227
0
SLANG_RAW("        {\n")
30228
0
SLANG_RAW("            int byteOffset = offset + i * __naturalStrideOf<T>();\n")
30229
0
SLANG_RAW("            T currentValue = buffer.LoadByteOffset<T>(byteOffset);\n")
30230
0
SLANG_RAW("            T newValue = currentValue + __arithmetic_cast<T>(v[i]);\n")
30231
0
SLANG_RAW("            buffer.StoreByteOffset(byteOffset, newValue);\n")
30232
0
SLANG_RAW("        }\n")
30233
0
SLANG_RAW("    }\n")
30234
0
SLANG_RAW("}\n")
30235
0
SLANG_RAW("\n")
30236
30237
0
} // if rw
30238
0
} // buffer type loop
30239
0
SLANG_RAW("#line 27501 \"hlsl.meta.slang\"")
30240
0
SLANG_RAW("\n")
30241
0
SLANG_RAW("\n")
30242
30243
0
static const struct {
30244
0
    bool isRW;
30245
0
    char const* type;
30246
0
} kStructuredBufferCases_[] =
30247
0
{
30248
0
    {true, "RWStructuredBuffer<IgnoredBufferElementType>"},
30249
0
    {false, "StructuredBuffer<IgnoredBufferElementType>"},
30250
0
};
30251
0
for(auto buffer : kStructuredBufferCases_) {
30252
0
SLANG_RAW("#line 27513 \"hlsl.meta.slang\"")
30253
0
SLANG_RAW("\n")
30254
0
SLANG_RAW("\n")
30255
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30256
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType,IgnoredBufferElementType>\n")
30257
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulPacked(\n")
30258
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
30259
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30260
0
SLANG_RAW("    constexpr int k,\n")
30261
0
SLANG_RAW("    ")
30262
0
SLANG_SPLICE(buffer.type
30263
0
)
30264
0
SLANG_RAW(" matrix,\n")
30265
0
SLANG_RAW("    int32_t matrixOffset,\n")
30266
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30267
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30268
0
SLANG_RAW("    constexpr bool transpose,\n")
30269
0
SLANG_RAW("    constexpr uint matrixStride\n")
30270
0
SLANG_RAW(")\n")
30271
0
SLANG_RAW("{\n")
30272
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
30273
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
30274
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30275
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
30276
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
30277
0
SLANG_RAW("    __target_switch\n")
30278
0
SLANG_RAW("    {\n")
30279
0
SLANG_RAW("    case spirv:\n")
30280
0
SLANG_RAW("        let m : int32_t = M;\n")
30281
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30282
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
30283
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30284
0
SLANG_RAW("        let matrixPtr = __getStructuredBufferPtr(matrix);\n")
30285
0
SLANG_RAW("\n")
30286
0
SLANG_RAW("        // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_cooperative_matrix.asciidoc#3x-cooperative-matrix-operands\n")
30287
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
30288
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
30289
0
SLANG_RAW("        {\n")
30290
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
30291
0
SLANG_RAW("        }\n")
30292
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
30293
0
SLANG_RAW("        {\n")
30294
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
30295
0
SLANG_RAW("        }\n")
30296
0
SLANG_RAW("        return spirv_asm\n")
30297
0
SLANG_RAW("        {\n")
30298
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulNV $input $inputInterpretationSpirv $matrixPtr $matrixOffset $matrixInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
30299
0
SLANG_RAW("        };\n")
30300
0
SLANG_RAW("    }\n")
30301
0
SLANG_RAW("}\n")
30302
0
SLANG_RAW("\n")
30303
0
SLANG_RAW("// specialized coopVecMatMul for non-packed inputs\n")
30304
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30305
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType,IgnoredBufferElementType>\n")
30306
0
SLANG_RAW("CoopVec<T, M> coopVecMatMul(\n")
30307
0
SLANG_RAW("    CoopVec<U, K> input,\n")
30308
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30309
0
SLANG_RAW("    ")
30310
0
SLANG_SPLICE(buffer.type
30311
0
)
30312
0
SLANG_RAW(" matrix,\n")
30313
0
SLANG_RAW("    int32_t matrixOffset,\n")
30314
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30315
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30316
0
SLANG_RAW("    constexpr bool transpose,\n")
30317
0
SLANG_RAW("    constexpr uint matrixStride\n")
30318
0
SLANG_RAW(")\n")
30319
0
SLANG_RAW("{\n")
30320
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30321
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
30322
0
SLANG_RAW("    return coopVecMatMulPacked<\n")
30323
0
SLANG_RAW("        T, M, K, U, IgnoredBufferElementType>(\n")
30324
0
SLANG_RAW("        input,\n")
30325
0
SLANG_RAW("        inputInterpretation,\n")
30326
0
SLANG_RAW("        K,\n")
30327
0
SLANG_RAW("        matrix,\n")
30328
0
SLANG_RAW("        matrixOffset,\n")
30329
0
SLANG_RAW("        matrixInterpretation,\n")
30330
0
SLANG_RAW("        memoryLayout,\n")
30331
0
SLANG_RAW("        transpose,\n")
30332
0
SLANG_RAW("        matrixStride);\n")
30333
0
SLANG_RAW("}\n")
30334
0
SLANG_RAW("\n")
30335
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30336
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAddPacked<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType, IgnoredBufferElementType>(\n")
30337
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
30338
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30339
0
SLANG_RAW("    constexpr int k,\n")
30340
0
SLANG_RAW("    ")
30341
0
SLANG_SPLICE(buffer.type
30342
0
)
30343
0
SLANG_RAW(" matrix,\n")
30344
0
SLANG_RAW("    int32_t matrixOffset,\n")
30345
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30346
0
SLANG_RAW("    ")
30347
0
SLANG_SPLICE(buffer.type
30348
0
)
30349
0
SLANG_RAW(" bias,\n")
30350
0
SLANG_RAW("    int32_t biasOffset,\n")
30351
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
30352
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30353
0
SLANG_RAW("    constexpr bool transpose,\n")
30354
0
SLANG_RAW("    constexpr uint matrixStride\n")
30355
0
SLANG_RAW(")\n")
30356
0
SLANG_RAW("{\n")
30357
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
30358
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
30359
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30360
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
30361
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
30362
0
SLANG_RAW("\n")
30363
0
SLANG_RAW("    __target_switch\n")
30364
0
SLANG_RAW("    {\n")
30365
0
SLANG_RAW("    case spirv:\n")
30366
0
SLANG_RAW("        let m : int32_t = M;\n")
30367
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30368
0
SLANG_RAW("        let biasInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(biasInterpretation);\n")
30369
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
30370
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30371
0
SLANG_RAW("        let matrixPtr = __getStructuredBufferPtr(matrix);\n")
30372
0
SLANG_RAW("        let biasPtr = __getStructuredBufferPtr(bias);\n")
30373
0
SLANG_RAW("\n")
30374
0
SLANG_RAW("        // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_cooperative_matrix.asciidoc#3x-cooperative-matrix-operands\n")
30375
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
30376
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
30377
0
SLANG_RAW("        {\n")
30378
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
30379
0
SLANG_RAW("        }\n")
30380
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
30381
0
SLANG_RAW("        {\n")
30382
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
30383
0
SLANG_RAW("        }\n")
30384
0
SLANG_RAW("\n")
30385
0
SLANG_RAW("        return spirv_asm\n")
30386
0
SLANG_RAW("        {\n")
30387
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulAddNV $input $inputInterpretationSpirv $matrixPtr $matrixOffset $matrixInterpretationSpirv $biasPtr $biasOffset $biasInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
30388
0
SLANG_RAW("        };\n")
30389
0
SLANG_RAW("    }\n")
30390
0
SLANG_RAW("}\n")
30391
0
SLANG_RAW("\n")
30392
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30393
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAdd<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType, IgnoredBufferElementType>(\n")
30394
0
SLANG_RAW("    CoopVec<U, K> input,\n")
30395
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30396
0
SLANG_RAW("    ")
30397
0
SLANG_SPLICE(buffer.type
30398
0
)
30399
0
SLANG_RAW(" matrix,\n")
30400
0
SLANG_RAW("    int32_t matrixOffset,\n")
30401
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30402
0
SLANG_RAW("    ")
30403
0
SLANG_SPLICE(buffer.type
30404
0
)
30405
0
SLANG_RAW(" bias,\n")
30406
0
SLANG_RAW("    int32_t biasOffset,\n")
30407
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
30408
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30409
0
SLANG_RAW("    constexpr bool transpose,\n")
30410
0
SLANG_RAW("    constexpr uint matrixStride\n")
30411
0
SLANG_RAW(")\n")
30412
0
SLANG_RAW("{\n")
30413
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30414
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
30415
0
SLANG_RAW("    return coopVecMatMulAddPacked<\n")
30416
0
SLANG_RAW("        T, M, K, U, IgnoredBufferElementType>(\n")
30417
0
SLANG_RAW("        input,\n")
30418
0
SLANG_RAW("        inputInterpretation,\n")
30419
0
SLANG_RAW("        K,\n")
30420
0
SLANG_RAW("        matrix,\n")
30421
0
SLANG_RAW("        matrixOffset,\n")
30422
0
SLANG_RAW("        matrixInterpretation,\n")
30423
0
SLANG_RAW("        bias,\n")
30424
0
SLANG_RAW("        biasOffset,\n")
30425
0
SLANG_RAW("        biasInterpretation,\n")
30426
0
SLANG_RAW("        memoryLayout,\n")
30427
0
SLANG_RAW("        transpose,\n")
30428
0
SLANG_RAW("        matrixStride);\n")
30429
0
SLANG_RAW("}\n")
30430
0
SLANG_RAW("\n")
30431
0
SLANG_RAW("//\n")
30432
0
SLANG_RAW("// Coop Vector accumulation\n")
30433
0
SLANG_RAW("//\n")
30434
0
SLANG_RAW("\n")
30435
30436
0
if(buffer.isRW)
30437
0
{
30438
0
SLANG_RAW("#line 27680 \"hlsl.meta.slang\"")
30439
0
SLANG_RAW("\n")
30440
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30441
0
SLANG_RAW("void coopVecOuterProductAccumulate<T : __BuiltinArithmeticType, let M : int, let N : int, IgnoredBufferElementType>(\n")
30442
0
SLANG_RAW("    CoopVec<T, M> a,\n")
30443
0
SLANG_RAW("    CoopVec<T, N> b,\n")
30444
0
SLANG_RAW("    ")
30445
0
SLANG_SPLICE(buffer.type
30446
0
)
30447
0
SLANG_RAW(" matrix,\n")
30448
0
SLANG_RAW("    int32_t matrixOffset,\n")
30449
0
SLANG_RAW("    constexpr uint matrixStride,\n")
30450
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30451
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30452
0
SLANG_RAW(")\n")
30453
0
SLANG_RAW("{\n")
30454
0
SLANG_RAW("    __target_switch\n")
30455
0
SLANG_RAW("    {\n")
30456
0
SLANG_RAW("    case spirv:\n")
30457
0
SLANG_RAW("        let matrixInterpretationSpirv : int = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30458
0
SLANG_RAW("        let memoryLayoutSpirv : int = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30459
0
SLANG_RAW("        let matrixPtr = __getStructuredBufferPtr(matrix);\n")
30460
0
SLANG_RAW("        spirv_asm\n")
30461
0
SLANG_RAW("        {\n")
30462
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30463
0
SLANG_RAW("            OpCooperativeVectorOuterProductAccumulateNV $matrixPtr $matrixOffset $a $b $memoryLayoutSpirv $matrixInterpretationSpirv $matrixStride;\n")
30464
0
SLANG_RAW("        };\n")
30465
0
SLANG_RAW("    }\n")
30466
0
SLANG_RAW("}\n")
30467
0
SLANG_RAW("\n")
30468
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30469
0
SLANG_RAW("void coopVecReduceSumAccumulate<T : __BuiltinArithmeticType, let N : int, IgnoredBufferElementType>(\n")
30470
0
SLANG_RAW("    CoopVec<T, N> v,\n")
30471
0
SLANG_RAW("    ")
30472
0
SLANG_SPLICE(buffer.type
30473
0
)
30474
0
SLANG_RAW(" buffer,\n")
30475
0
SLANG_RAW("    int32_t offset\n")
30476
0
SLANG_RAW(")\n")
30477
0
SLANG_RAW("{\n")
30478
0
SLANG_RAW("    __target_switch\n")
30479
0
SLANG_RAW("    {\n")
30480
0
SLANG_RAW("    case spirv:\n")
30481
0
SLANG_RAW("        let bufferPtr = __getStructuredBufferPtr(buffer);\n")
30482
0
SLANG_RAW("        spirv_asm\n")
30483
0
SLANG_RAW("        {\n")
30484
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30485
0
SLANG_RAW("            OpCooperativeVectorReduceSumAccumulateNV $bufferPtr $offset $v;\n")
30486
0
SLANG_RAW("        };\n")
30487
0
SLANG_RAW("    }\n")
30488
0
SLANG_RAW("}\n")
30489
0
SLANG_RAW("\n")
30490
30491
0
} // if rw
30492
0
} // buffer type loop
30493
0
SLANG_RAW("#line 27728 \"hlsl.meta.slang\"")
30494
0
SLANG_RAW("\n")
30495
0
SLANG_RAW("\n")
30496
0
SLANG_RAW("\n")
30497
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30498
0
SLANG_RAW("void coopVecOuterProductAccumulate<T : __BuiltinArithmeticType, let M : int, let N : int, U : __BuiltinArithmeticType, let IgnoredBufferSize : int>(\n")
30499
0
SLANG_RAW("    CoopVec<T, M> a,\n")
30500
0
SLANG_RAW("    CoopVec<T, N> b,\n")
30501
0
SLANG_RAW("    __ref groupshared U[IgnoredBufferSize] matrix,\n")
30502
0
SLANG_RAW("    int32_t matrixOffset,\n")
30503
0
SLANG_RAW("    constexpr uint matrixStride,\n")
30504
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30505
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30506
0
SLANG_RAW(")\n")
30507
0
SLANG_RAW("{\n")
30508
0
SLANG_RAW("    __target_switch\n")
30509
0
SLANG_RAW("    {\n")
30510
0
SLANG_RAW("    case spirv:\n")
30511
0
SLANG_RAW("        let matrixInterpretationSpirv : int = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30512
0
SLANG_RAW("        let memoryLayoutSpirv : int = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30513
0
SLANG_RAW("        spirv_asm\n")
30514
0
SLANG_RAW("        {\n")
30515
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30516
0
SLANG_RAW("            OpCooperativeVectorOuterProductAccumulateNV &matrix $matrixOffset $a $b $memoryLayoutSpirv $matrixInterpretationSpirv $matrixStride;\n")
30517
0
SLANG_RAW("        };\n")
30518
0
SLANG_RAW("    }\n")
30519
0
SLANG_RAW("}\n")
30520
0
SLANG_RAW("\n")
30521
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30522
0
SLANG_RAW("void coopVecReduceSumAccumulate<T : __BuiltinArithmeticType, let N : int, U, let IgnoredBufferSize : int>(\n")
30523
0
SLANG_RAW("    CoopVec<T, N> v,\n")
30524
0
SLANG_RAW("    __ref groupshared U[IgnoredBufferSize] buffer,\n")
30525
0
SLANG_RAW("    int32_t offset\n")
30526
0
SLANG_RAW(")\n")
30527
0
SLANG_RAW("{\n")
30528
0
SLANG_RAW("    __target_switch\n")
30529
0
SLANG_RAW("    {\n")
30530
0
SLANG_RAW("    case spirv:\n")
30531
0
SLANG_RAW("        spirv_asm\n")
30532
0
SLANG_RAW("        {\n")
30533
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30534
0
SLANG_RAW("            OpCooperativeVectorReduceSumAccumulateNV &buffer $offset $v;\n")
30535
0
SLANG_RAW("        };\n")
30536
0
SLANG_RAW("    }\n")
30537
0
SLANG_RAW("}\n")
30538
0
SLANG_RAW("\n")
30539
0
SLANG_RAW("// Pointer overloads for coopvector operations.\n")
30540
0
SLANG_RAW("\n")
30541
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30542
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType>\n")
30543
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulPacked(\n")
30544
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
30545
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30546
0
SLANG_RAW("    constexpr int k,\n")
30547
0
SLANG_RAW("    void* matrixPtr,\n")
30548
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30549
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30550
0
SLANG_RAW("    constexpr bool transpose,\n")
30551
0
SLANG_RAW("    constexpr uint matrixStride\n")
30552
0
SLANG_RAW(")\n")
30553
0
SLANG_RAW("{\n")
30554
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
30555
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
30556
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30557
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
30558
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
30559
0
SLANG_RAW("    __target_switch\n")
30560
0
SLANG_RAW("    {\n")
30561
0
SLANG_RAW("    case spirv:\n")
30562
0
SLANG_RAW("        let m : int32_t = M;\n")
30563
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30564
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
30565
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30566
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
30567
0
SLANG_RAW("        let zero = 0;\n")
30568
0
SLANG_RAW("        let cvtMatPtr = (Ptr<T[]>)matrixPtr;\n")
30569
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
30570
0
SLANG_RAW("        {\n")
30571
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
30572
0
SLANG_RAW("        }\n")
30573
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
30574
0
SLANG_RAW("        {\n")
30575
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
30576
0
SLANG_RAW("        }\n")
30577
0
SLANG_RAW("        return spirv_asm\n")
30578
0
SLANG_RAW("        {\n")
30579
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulNV $input $inputInterpretationSpirv $cvtMatPtr $zero $matrixInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
30580
0
SLANG_RAW("        };\n")
30581
0
SLANG_RAW("    }\n")
30582
0
SLANG_RAW("}\n")
30583
0
SLANG_RAW("\n")
30584
0
SLANG_RAW("// specialized coopVecMatMul for non-packed inputs\n")
30585
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30586
0
SLANG_RAW("__generic<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType>\n")
30587
0
SLANG_RAW("CoopVec<T, M> coopVecMatMul(\n")
30588
0
SLANG_RAW("    CoopVec<U, K> input,\n")
30589
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30590
0
SLANG_RAW("    void* matrix,\n")
30591
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30592
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30593
0
SLANG_RAW("    constexpr bool transpose,\n")
30594
0
SLANG_RAW("    constexpr uint matrixStride\n")
30595
0
SLANG_RAW(")\n")
30596
0
SLANG_RAW("{\n")
30597
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30598
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
30599
0
SLANG_RAW("    return coopVecMatMulPacked<\n")
30600
0
SLANG_RAW("        T, M, K, U>(\n")
30601
0
SLANG_RAW("        input,\n")
30602
0
SLANG_RAW("        inputInterpretation,\n")
30603
0
SLANG_RAW("        K,\n")
30604
0
SLANG_RAW("        matrix,\n")
30605
0
SLANG_RAW("        matrixInterpretation,\n")
30606
0
SLANG_RAW("        memoryLayout,\n")
30607
0
SLANG_RAW("        transpose,\n")
30608
0
SLANG_RAW("        matrixStride);\n")
30609
0
SLANG_RAW("}\n")
30610
0
SLANG_RAW("\n")
30611
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30612
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAddPacked<T : __BuiltinArithmeticType, let M : int, let PackedK : int, U : __BuiltinArithmeticType>(\n")
30613
0
SLANG_RAW("    CoopVec<U, PackedK> input,\n")
30614
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30615
0
SLANG_RAW("    constexpr int k,\n")
30616
0
SLANG_RAW("    void* matrixPtr,\n")
30617
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30618
0
SLANG_RAW("    void* biasPtr,\n")
30619
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
30620
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30621
0
SLANG_RAW("    constexpr bool transpose,\n")
30622
0
SLANG_RAW("    constexpr uint matrixStride\n")
30623
0
SLANG_RAW(")\n")
30624
0
SLANG_RAW("{\n")
30625
0
SLANG_RAW("    static_assert(__isPackedInputInterpretation(inputInterpretation) || k == PackedK\n")
30626
0
SLANG_RAW("                 , \"for non-packed inputInterpretation values k must be equal to the input vector length\");\n")
30627
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30628
0
SLANG_RAW("                || k <= __inputInterpretationPackingFactor(inputInterpretation)*PackedK\n")
30629
0
SLANG_RAW("                 , \"for packed inputInterpretation values k must be less than or equal to the input vector length times the packing factor\");\n")
30630
0
SLANG_RAW("\n")
30631
0
SLANG_RAW("    __target_switch\n")
30632
0
SLANG_RAW("    {\n")
30633
0
SLANG_RAW("    case spirv:\n")
30634
0
SLANG_RAW("        let m : int32_t = M;\n")
30635
0
SLANG_RAW("        let matrixInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30636
0
SLANG_RAW("        let biasInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(biasInterpretation);\n")
30637
0
SLANG_RAW("        let inputInterpretationSpirv : int32_t = __getSpvCoopVecComponentType(inputInterpretation);\n")
30638
0
SLANG_RAW("        let memoryLayoutSpirv : int32_t = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30639
0
SLANG_RAW("        let zero : int32_t = 0;\n")
30640
0
SLANG_RAW("        let cvtMatPtr = (Ptr<T[]>)matrixPtr;\n")
30641
0
SLANG_RAW("        let cvtBiasPtr = (Ptr<T[]>)biasPtr;\n")
30642
0
SLANG_RAW("        int operands = 0; // NoneKHR\n")
30643
0
SLANG_RAW("        if (__isSignedInt<U>())\n")
30644
0
SLANG_RAW("        {\n")
30645
0
SLANG_RAW("            operands |= 0x02; // MatrixBSignedComponentsKHR\n")
30646
0
SLANG_RAW("        }\n")
30647
0
SLANG_RAW("        if (__isSignedInt<T>())\n")
30648
0
SLANG_RAW("        {\n")
30649
0
SLANG_RAW("            operands |= 0x08; // MatrixResultSignedComponentsKHR\n")
30650
0
SLANG_RAW("        }\n")
30651
0
SLANG_RAW("        return spirv_asm\n")
30652
0
SLANG_RAW("        {\n")
30653
0
SLANG_RAW("            result:$$CoopVec<T, M> = OpCooperativeVectorMatrixMulAddNV $input $inputInterpretationSpirv $cvtMatPtr $zero $matrixInterpretationSpirv $cvtBiasPtr $zero $biasInterpretationSpirv $m $k $memoryLayoutSpirv $transpose $matrixStride !operands;\n")
30654
0
SLANG_RAW("        };\n")
30655
0
SLANG_RAW("    }\n")
30656
0
SLANG_RAW("}\n")
30657
0
SLANG_RAW("\n")
30658
0
SLANG_RAW("[require(spirv, cooperative_vector)]\n")
30659
0
SLANG_RAW("CoopVec<T, M> coopVecMatMulAdd<T : __BuiltinArithmeticType, let M : int, let K : int, U : __BuiltinArithmeticType>(\n")
30660
0
SLANG_RAW("    CoopVec<U, K> input,\n")
30661
0
SLANG_RAW("    constexpr CoopVecComponentType inputInterpretation,\n")
30662
0
SLANG_RAW("    void* matrix,\n")
30663
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30664
0
SLANG_RAW("    void* bias,\n")
30665
0
SLANG_RAW("    constexpr CoopVecComponentType biasInterpretation,\n")
30666
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30667
0
SLANG_RAW("    constexpr bool transpose,\n")
30668
0
SLANG_RAW("    constexpr uint matrixStride\n")
30669
0
SLANG_RAW(")\n")
30670
0
SLANG_RAW("{\n")
30671
0
SLANG_RAW("    static_assert(!__isPackedInputInterpretation(inputInterpretation)\n")
30672
0
SLANG_RAW("                 , \"for packed inputInterpretation values please use coopVecMatMulPacked and specify k manually\");\n")
30673
0
SLANG_RAW("    return coopVecMatMulAddPacked<\n")
30674
0
SLANG_RAW("        T, M, K, U>(\n")
30675
0
SLANG_RAW("        input,\n")
30676
0
SLANG_RAW("        inputInterpretation,\n")
30677
0
SLANG_RAW("        K,\n")
30678
0
SLANG_RAW("        matrix,\n")
30679
0
SLANG_RAW("        matrixInterpretation,\n")
30680
0
SLANG_RAW("        bias,\n")
30681
0
SLANG_RAW("        biasInterpretation,\n")
30682
0
SLANG_RAW("        memoryLayout,\n")
30683
0
SLANG_RAW("        transpose,\n")
30684
0
SLANG_RAW("        matrixStride);\n")
30685
0
SLANG_RAW("}\n")
30686
0
SLANG_RAW("\n")
30687
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30688
0
SLANG_RAW("void coopVecOuterProductAccumulate<T : __BuiltinArithmeticType, let M : int, let N : int>(\n")
30689
0
SLANG_RAW("    CoopVec<T, M> a,\n")
30690
0
SLANG_RAW("    CoopVec<T, N> b,\n")
30691
0
SLANG_RAW("    void* matrixPtr,\n")
30692
0
SLANG_RAW("    constexpr uint matrixStride,\n")
30693
0
SLANG_RAW("    constexpr CoopVecMatrixLayout memoryLayout,\n")
30694
0
SLANG_RAW("    constexpr CoopVecComponentType matrixInterpretation,\n")
30695
0
SLANG_RAW(")\n")
30696
0
SLANG_RAW("{\n")
30697
0
SLANG_RAW("    let zero : int32_t = 0;\n")
30698
0
SLANG_RAW("    __target_switch\n")
30699
0
SLANG_RAW("    {\n")
30700
0
SLANG_RAW("    case spirv:\n")
30701
0
SLANG_RAW("        let matrixInterpretationSpirv : int = __getSpvCoopVecComponentType(matrixInterpretation);\n")
30702
0
SLANG_RAW("        let memoryLayoutSpirv : int = __getSpvCoopVecMatrixLayout(memoryLayout);\n")
30703
0
SLANG_RAW("        let cvtMatrixPtr = (Ptr<T[]>)matrixPtr;\n")
30704
0
SLANG_RAW("        spirv_asm\n")
30705
0
SLANG_RAW("        {\n")
30706
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30707
0
SLANG_RAW("            OpCooperativeVectorOuterProductAccumulateNV $cvtMatrixPtr $zero $a $b $memoryLayoutSpirv $matrixInterpretationSpirv $matrixStride;\n")
30708
0
SLANG_RAW("        };\n")
30709
0
SLANG_RAW("    }\n")
30710
0
SLANG_RAW("}\n")
30711
0
SLANG_RAW("\n")
30712
0
SLANG_RAW("[require(spirv, cooperative_vector_training)]\n")
30713
0
SLANG_RAW("void coopVecReduceSumAccumulate<T : __BuiltinArithmeticType, let N : int>(\n")
30714
0
SLANG_RAW("    CoopVec<T, N> v,\n")
30715
0
SLANG_RAW("    void* buffer\n")
30716
0
SLANG_RAW(")\n")
30717
0
SLANG_RAW("{\n")
30718
0
SLANG_RAW("    let zero : int32_t = 0;\n")
30719
0
SLANG_RAW("    let bufferPtr = (Ptr<T[]>)(buffer);\n")
30720
0
SLANG_RAW("    __target_switch\n")
30721
0
SLANG_RAW("    {\n")
30722
0
SLANG_RAW("    case spirv:\n")
30723
0
SLANG_RAW("        spirv_asm\n")
30724
0
SLANG_RAW("        {\n")
30725
0
SLANG_RAW("            OpCapability CooperativeVectorTrainingNV;\n")
30726
0
SLANG_RAW("            OpCooperativeVectorReduceSumAccumulateNV $bufferPtr $zero $v;\n")
30727
0
SLANG_RAW("        };\n")
30728
0
SLANG_RAW("    }\n")
30729
0
SLANG_RAW("}\n")
30730
0
SLANG_RAW("\n")
30731
0
SLANG_RAW("//@public:\n")
30732
0
SLANG_RAW("\n")
30733
0
SLANG_RAW("/// Mark a variable as being workgroup uniform.\n")
30734
0
SLANG_RAW("/// @param v The variable to mark as workgroup uniform.\n")
30735
0
SLANG_RAW("/// @return The value of `v`.\n")
30736
0
SLANG_RAW("/// @remarks This intrinsic maps to `workgroupUniformLoad` when targeting WGSL and is a no-op on other targets.\n")
30737
0
SLANG_RAW("/// WGSL is strict on uniformity, and this intrinsic is needed to mark a variable as workgroup uniform in order\n")
30738
0
SLANG_RAW("// to silence uniformity errors in certain cases.\n")
30739
0
SLANG_RAW("T workgroupUniformLoad<T>(__ref T v)\n")
30740
0
SLANG_RAW("{\n")
30741
0
SLANG_RAW("    __target_switch\n")
30742
0
SLANG_RAW("    {\n")
30743
0
SLANG_RAW("    case wgsl:\n")
30744
0
SLANG_RAW("        __intrinsic_asm \"workgroupUniformLoad(&($0))\";\n")
30745
0
SLANG_RAW("    default:\n")
30746
0
SLANG_RAW("        return v;\n")
30747
0
SLANG_RAW("    }\n")
30748
0
SLANG_RAW("}\n")
30749
0
SLANG_RAW("\n")
30750
0
SLANG_RAW("//\n")
30751
0
SLANG_RAW("// HLSL Pack/Unpack Math Intrinsics\n")
30752
0
SLANG_RAW("//\n")
30753
0
SLANG_RAW("// These were introduced in SM 6.6 but requirements are dropped to SM 5.0 here\n")
30754
0
SLANG_RAW("// to expose these intrinsics on targets that do not have SM 6.6 features.\n")
30755
0
SLANG_RAW("//\n")
30756
0
SLANG_RAW("\n")
30757
0
SLANG_RAW("//@public:\n")
30758
0
SLANG_RAW("\n")
30759
0
SLANG_RAW("typealias uint8_t4_packed = uint;\n")
30760
0
SLANG_RAW("typealias int8_t4_packed = uint;\n")
30761
0
SLANG_RAW("\n")
30762
0
SLANG_RAW("/// Unpack 4 signed 8-bit values into a vector of 16 bit integers.\n")
30763
0
SLANG_RAW("[__readNone]\n")
30764
0
SLANG_RAW("[ForceInline]\n")
30765
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30766
0
SLANG_RAW("int16_t4 unpack_s8s16(int8_t4_packed packed)\n")
30767
0
SLANG_RAW("{\n")
30768
0
SLANG_RAW("    return unpackInt4x8ToInt16(packed);\n")
30769
0
SLANG_RAW("}\n")
30770
0
SLANG_RAW("\n")
30771
0
SLANG_RAW("/// Unpack 4 unsigned 8-bit values into a vector of 16 bit integers.\n")
30772
0
SLANG_RAW("[__readNone]\n")
30773
0
SLANG_RAW("[ForceInline]\n")
30774
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30775
0
SLANG_RAW("uint16_t4 unpack_u8u16(uint8_t4_packed packed)\n")
30776
0
SLANG_RAW("{\n")
30777
0
SLANG_RAW("    return unpackUint4x8ToUint16(packed);\n")
30778
0
SLANG_RAW("}\n")
30779
0
SLANG_RAW("\n")
30780
0
SLANG_RAW("/// Unpack 4 signed 8-bit values into a vector of 32 bit integers.\n")
30781
0
SLANG_RAW("[__readNone]\n")
30782
0
SLANG_RAW("[ForceInline]\n")
30783
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30784
0
SLANG_RAW("int32_t4 unpack_s8s32(int8_t4_packed packed)\n")
30785
0
SLANG_RAW("{\n")
30786
0
SLANG_RAW("    return unpackInt4x8ToInt32(packed);\n")
30787
0
SLANG_RAW("}\n")
30788
0
SLANG_RAW("\n")
30789
0
SLANG_RAW("/// Unpack 4 unsigned 8-bit values into a vector of 32 bit integers.\n")
30790
0
SLANG_RAW("[__readNone]\n")
30791
0
SLANG_RAW("[ForceInline]\n")
30792
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30793
0
SLANG_RAW("uint32_t4 unpack_u8u32(uint8_t4_packed packed)\n")
30794
0
SLANG_RAW("{\n")
30795
0
SLANG_RAW("    return unpackUint4x8ToUint32(packed);\n")
30796
0
SLANG_RAW("}\n")
30797
0
SLANG_RAW("\n")
30798
0
SLANG_RAW("/// Pack a vector of 4 unsigned 32/16 bit integers into a packed value of 4 8-bit integers, dropping unused bits.\n")
30799
0
SLANG_RAW("[__readNone]\n")
30800
0
SLANG_RAW("[ForceInline]\n")
30801
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30802
0
SLANG_RAW("uint8_t4_packed pack_u8(uint32_t4 unpackedValue)\n")
30803
0
SLANG_RAW("{\n")
30804
0
SLANG_RAW("    return packUint4x8(unpackedValue);\n")
30805
0
SLANG_RAW("}\n")
30806
0
SLANG_RAW("\n")
30807
0
SLANG_RAW("/// Pack a vector of 4 signed 32/16 bit integers into a packed value of 4 8-bit integers, dropping unused bits.\n")
30808
0
SLANG_RAW("[__readNone]\n")
30809
0
SLANG_RAW("[ForceInline]\n")
30810
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30811
0
SLANG_RAW("int8_t4_packed pack_s8(int32_t4 unpackedValue)\n")
30812
0
SLANG_RAW("{\n")
30813
0
SLANG_RAW("    return packInt4x8(unpackedValue);\n")
30814
0
SLANG_RAW("}\n")
30815
0
SLANG_RAW("\n")
30816
0
SLANG_RAW("[__readNone]\n")
30817
0
SLANG_RAW("[ForceInline]\n")
30818
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30819
0
SLANG_RAW("uint8_t4_packed pack_u8(uint16_t4 unpackedValue)\n")
30820
0
SLANG_RAW("{\n")
30821
0
SLANG_RAW("    return packUint4x8(unpackedValue);\n")
30822
0
SLANG_RAW("}\n")
30823
0
SLANG_RAW("\n")
30824
0
SLANG_RAW("[__readNone]\n")
30825
0
SLANG_RAW("[ForceInline]\n")
30826
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30827
0
SLANG_RAW("int8_t4_packed pack_s8(int16_t4 unpackedValue)\n")
30828
0
SLANG_RAW("{\n")
30829
0
SLANG_RAW("    return packInt4x8(unpackedValue);\n")
30830
0
SLANG_RAW("}\n")
30831
0
SLANG_RAW("\n")
30832
0
SLANG_RAW("/// Pack a vector of 4 unsigned 32/16 bit integers into a packed value of 4 8-bit integers,\n")
30833
0
SLANG_RAW("/// clamping each value to the range [0, 255] to ensure it fits within 8 bits.\n")
30834
0
SLANG_RAW("[__readNone]\n")
30835
0
SLANG_RAW("[ForceInline]\n")
30836
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30837
0
SLANG_RAW("uint8_t4_packed pack_clamp_u8(int32_t4 unpackedValue)\n")
30838
0
SLANG_RAW("{\n")
30839
0
SLANG_RAW("    return packUint4x8Clamp(unpackedValue);\n")
30840
0
SLANG_RAW("}\n")
30841
0
SLANG_RAW("\n")
30842
0
SLANG_RAW("/// Pack a vector of 4 signed 32/16 bit integers into a packed value of 4 8-bit integers,\n")
30843
0
SLANG_RAW("/// clamping each value to the range [-128, 127] to ensure it fits within 8 bits.\n")
30844
0
SLANG_RAW("[__readNone]\n")
30845
0
SLANG_RAW("[ForceInline]\n")
30846
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30847
0
SLANG_RAW("int8_t4_packed pack_clamp_s8(int32_t4 unpackedValue)\n")
30848
0
SLANG_RAW("{\n")
30849
0
SLANG_RAW("    return packInt4x8Clamp(unpackedValue);\n")
30850
0
SLANG_RAW("}\n")
30851
0
SLANG_RAW("\n")
30852
0
SLANG_RAW("[__readNone]\n")
30853
0
SLANG_RAW("[ForceInline]\n")
30854
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30855
0
SLANG_RAW("uint8_t4_packed pack_clamp_u8(int16_t4 unpackedValue)\n")
30856
0
SLANG_RAW("{\n")
30857
0
SLANG_RAW("    return packUint4x8Clamp(unpackedValue);\n")
30858
0
SLANG_RAW("}\n")
30859
0
SLANG_RAW("\n")
30860
0
SLANG_RAW("[__readNone]\n")
30861
0
SLANG_RAW("[ForceInline]\n")
30862
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30863
0
SLANG_RAW("int8_t4_packed pack_clamp_s8(int16_t4 unpackedValue)\n")
30864
0
SLANG_RAW("{\n")
30865
0
SLANG_RAW("    return packInt4x8Clamp(unpackedValue);\n")
30866
0
SLANG_RAW("}\n")
30867
0
SLANG_RAW("\n")
30868
0
SLANG_RAW("// Work-graphs\n")
30869
0
SLANG_RAW("\n")
30870
0
SLANG_RAW("//@public:\n")
30871
0
SLANG_RAW("/// read-only input to Broadcasting launch node.\n")
30872
0
SLANG_RAW("__generic<T>\n")
30873
0
SLANG_RAW("//TODO: DispatchNodeInputRecord should be available only for broadcasting node shader.\n")
30874
0
SLANG_RAW("//[require(broadcasting_node)]\n")
30875
0
SLANG_RAW("[require(spirv)]\n")
30876
0
SLANG_RAW("struct DispatchNodeInputRecord\n")
30877
0
SLANG_RAW("{\n")
30878
0
SLANG_RAW("    /// Provide an access to a record object that only holds a single record.\n")
30879
0
SLANG_RAW("    NodePayloadPtr<T> Get()\n")
30880
0
SLANG_RAW("    {\n")
30881
0
SLANG_RAW("        int index = 0;\n")
30882
0
SLANG_RAW("        __target_switch\n")
30883
0
SLANG_RAW("        {\n")
30884
0
SLANG_RAW("        case spirv:\n")
30885
0
SLANG_RAW("            return spirv_asm\n")
30886
0
SLANG_RAW("            {\n")
30887
0
SLANG_RAW("                %in_payload_t = OpTypeNodePayloadArrayAMDX $$T;\n")
30888
0
SLANG_RAW("                %in_payload_ptr_t = OpTypePointer NodePayloadAMDX %in_payload_t;\n")
30889
0
SLANG_RAW("                %var = OpVariable %in_payload_ptr_t NodePayloadAMDX;\n")
30890
0
SLANG_RAW("                result : $$NodePayloadPtr<T> = OpAccessChain %var $index;\n")
30891
0
SLANG_RAW("            };\n")
30892
0
SLANG_RAW("        }\n")
30893
0
SLANG_RAW("    }\n")
30894
0
SLANG_RAW("};\n")
30895
0
SLANG_RAW("\n")
30896
0
SLANG_RAW("//\n")
30897
0
SLANG_RAW("// Pack/Unpack Intrinsics\n")
30898
0
SLANG_RAW("//\n")
30899
0
SLANG_RAW("\n")
30900
0
SLANG_RAW("//@hidden:\n")
30901
0
SLANG_RAW("\n")
30902
0
SLANG_RAW("[__readNone]\n")
30903
0
SLANG_RAW("[ForceInline]\n")
30904
0
SLANG_RAW("uint16_t __lsbAsUint16(uint32_t val)\n")
30905
0
SLANG_RAW("{\n")
30906
0
SLANG_RAW("    return uint16_t(val & 0xFFU);\n")
30907
0
SLANG_RAW("}\n")
30908
0
SLANG_RAW("\n")
30909
0
SLANG_RAW("[__readNone]\n")
30910
0
SLANG_RAW("[ForceInline]\n")
30911
0
SLANG_RAW("uint32_t __lsbAsUint32(uint32_t val)\n")
30912
0
SLANG_RAW("{\n")
30913
0
SLANG_RAW("    return (val & 0xFFU);\n")
30914
0
SLANG_RAW("}\n")
30915
0
SLANG_RAW("\n")
30916
0
SLANG_RAW("[__readNone]\n")
30917
0
SLANG_RAW("[ForceInline]\n")
30918
0
SLANG_RAW("int8_t __lsbAsInt8(uint32_t val)\n")
30919
0
SLANG_RAW("{\n")
30920
0
SLANG_RAW("    return int8_t(val);\n")
30921
0
SLANG_RAW("}\n")
30922
0
SLANG_RAW("\n")
30923
0
SLANG_RAW("[__readNone]\n")
30924
0
SLANG_RAW("[ForceInline]\n")
30925
0
SLANG_RAW("int16_t __lsbAsInt16(uint32_t val)\n")
30926
0
SLANG_RAW("{\n")
30927
0
SLANG_RAW("    return int16_t(__lsbAsInt8(val));\n")
30928
0
SLANG_RAW("}\n")
30929
0
SLANG_RAW("\n")
30930
0
SLANG_RAW("[__readNone]\n")
30931
0
SLANG_RAW("[ForceInline]\n")
30932
0
SLANG_RAW("int32_t __lsbAsInt32(uint32_t val)\n")
30933
0
SLANG_RAW("{\n")
30934
0
SLANG_RAW("    return int32_t(__lsbAsInt8(val));\n")
30935
0
SLANG_RAW("}\n")
30936
0
SLANG_RAW("\n")
30937
0
SLANG_RAW("[__readNone]\n")
30938
0
SLANG_RAW("[ForceInline]\n")
30939
0
SLANG_RAW("uint32_t2 __unpackUint2x16ToUint32(uint packedValue)\n")
30940
0
SLANG_RAW("{\n")
30941
0
SLANG_RAW("    return uint32_t2(packedValue & 0xFFFFU, packedValue >> 16U);\n")
30942
0
SLANG_RAW("}\n")
30943
0
SLANG_RAW("\n")
30944
0
SLANG_RAW("[__readNone]\n")
30945
0
SLANG_RAW("[ForceInline]\n")
30946
0
SLANG_RAW("int32_t2 __unpackInt2x16ToInt32(uint packedValue)\n")
30947
0
SLANG_RAW("{\n")
30948
0
SLANG_RAW("    int signedValue = int(packedValue);\n")
30949
0
SLANG_RAW("    return int32_t2(signedValue << 16U, signedValue) >> 16U;\n")
30950
0
SLANG_RAW("}\n")
30951
0
SLANG_RAW("\n")
30952
0
SLANG_RAW("[__readNone]\n")
30953
0
SLANG_RAW("[ForceInline]\n")
30954
0
SLANG_RAW("uint __packUint2x16(uint32_t2 unpackedValue)\n")
30955
0
SLANG_RAW("{\n")
30956
0
SLANG_RAW("    return (unpackedValue.x & 0xFFFF) | (unpackedValue.y << 16U);\n")
30957
0
SLANG_RAW("}\n")
30958
0
SLANG_RAW("\n")
30959
0
SLANG_RAW("[__readNone]\n")
30960
0
SLANG_RAW("[ForceInline]\n")
30961
0
SLANG_RAW("uint __packInt2x16(int32_t2 unpackedValue)\n")
30962
0
SLANG_RAW("{\n")
30963
0
SLANG_RAW("    return uint((unpackedValue.x & 0xFFFF) | (unpackedValue.y << 16U));\n")
30964
0
SLANG_RAW("}\n")
30965
0
SLANG_RAW("\n")
30966
0
SLANG_RAW("//@public:\n")
30967
0
SLANG_RAW("\n")
30968
0
SLANG_RAW("/// Unpack 4 unsigned 8-bit values into a vector of 32 bit integers.\n")
30969
0
SLANG_RAW("[__readNone]\n")
30970
0
SLANG_RAW("[ForceInline]\n")
30971
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30972
0
SLANG_RAW("uint32_t4 unpackUint4x8ToUint32(uint packedValue)\n")
30973
0
SLANG_RAW("{\n")
30974
0
SLANG_RAW("    __target_switch\n")
30975
0
SLANG_RAW("    {\n")
30976
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"unpack_u8u32\";\n")
30977
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack4xU8\";\n")
30978
0
SLANG_RAW("    case spirv:\n")
30979
0
SLANG_RAW("        return spirv_asm\n")
30980
0
SLANG_RAW("        {\n")
30981
0
SLANG_RAW("            %u8Vec = OpBitcast $$vector<uint8_t, 4> $packedValue;\n")
30982
0
SLANG_RAW("            result:$$vector<uint32_t, 4> = OpUConvert %u8Vec\n")
30983
0
SLANG_RAW("        };\n")
30984
0
SLANG_RAW("    default:\n")
30985
0
SLANG_RAW("        return uint32_t4\n")
30986
0
SLANG_RAW("        (\n")
30987
0
SLANG_RAW("            __lsbAsUint32(packedValue),\n")
30988
0
SLANG_RAW("            __lsbAsUint32(packedValue >> 8U),\n")
30989
0
SLANG_RAW("            __lsbAsUint32(packedValue >> 16U),\n")
30990
0
SLANG_RAW("            uint32_t(packedValue >> 24U),\n")
30991
0
SLANG_RAW("        );\n")
30992
0
SLANG_RAW("    }\n")
30993
0
SLANG_RAW("}\n")
30994
0
SLANG_RAW("\n")
30995
0
SLANG_RAW("/// Unpack 4 unsigned 8-bit values into a vector of 16 bit integers.\n")
30996
0
SLANG_RAW("[__readNone]\n")
30997
0
SLANG_RAW("[ForceInline]\n")
30998
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
30999
0
SLANG_RAW("uint16_t4 unpackUint4x8ToUint16(uint packedValue)\n")
31000
0
SLANG_RAW("{\n")
31001
0
SLANG_RAW("    __target_switch\n")
31002
0
SLANG_RAW("    {\n")
31003
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"unpack_u8u16\";\n")
31004
0
SLANG_RAW("    case spirv:\n")
31005
0
SLANG_RAW("        return spirv_asm\n")
31006
0
SLANG_RAW("        {\n")
31007
0
SLANG_RAW("            %u8Vec = OpBitcast $$vector<uint8_t, 4> $packedValue;\n")
31008
0
SLANG_RAW("            result:$$vector<uint16_t, 4> = OpUConvert %u8Vec\n")
31009
0
SLANG_RAW("        };\n")
31010
0
SLANG_RAW("    default:\n")
31011
0
SLANG_RAW("        return uint16_t4\n")
31012
0
SLANG_RAW("        (\n")
31013
0
SLANG_RAW("            __lsbAsUint16(packedValue),\n")
31014
0
SLANG_RAW("            __lsbAsUint16(packedValue >> 8U),\n")
31015
0
SLANG_RAW("            __lsbAsUint16(packedValue >> 16U),\n")
31016
0
SLANG_RAW("            uint16_t(packedValue >> 24U),\n")
31017
0
SLANG_RAW("        );\n")
31018
0
SLANG_RAW("    }\n")
31019
0
SLANG_RAW("}\n")
31020
0
SLANG_RAW("\n")
31021
0
SLANG_RAW("/// Unpack 4 signed 8-bit values into a vector of 32 bit integers.\n")
31022
0
SLANG_RAW("[__readNone]\n")
31023
0
SLANG_RAW("[ForceInline]\n")
31024
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31025
0
SLANG_RAW("int32_t4 unpackInt4x8ToInt32(uint packedValue)\n")
31026
0
SLANG_RAW("{\n")
31027
0
SLANG_RAW("    __target_switch\n")
31028
0
SLANG_RAW("    {\n")
31029
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"unpack_s8s32\";\n")
31030
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack4xI8\";\n")
31031
0
SLANG_RAW("    case spirv:\n")
31032
0
SLANG_RAW("        return spirv_asm\n")
31033
0
SLANG_RAW("        {\n")
31034
0
SLANG_RAW("            %s8Vec = OpBitcast $$vector<int8_t, 4> $packedValue;\n")
31035
0
SLANG_RAW("            result:$$vector<int32_t, 4> = OpSConvert %s8Vec\n")
31036
0
SLANG_RAW("        };\n")
31037
0
SLANG_RAW("    default:\n")
31038
0
SLANG_RAW("        return int32_t4\n")
31039
0
SLANG_RAW("        (\n")
31040
0
SLANG_RAW("            __lsbAsInt32(packedValue),\n")
31041
0
SLANG_RAW("            __lsbAsInt32(packedValue >> 8U),\n")
31042
0
SLANG_RAW("            __lsbAsInt32(packedValue >> 16U),\n")
31043
0
SLANG_RAW("            int32_t(int8_t(packedValue >> 24U)),\n")
31044
0
SLANG_RAW("        );\n")
31045
0
SLANG_RAW("    }\n")
31046
0
SLANG_RAW("}\n")
31047
0
SLANG_RAW("\n")
31048
0
SLANG_RAW("/// Unpack 4 signed 8-bit values into a vector of 16 bit integers.\n")
31049
0
SLANG_RAW("[__readNone]\n")
31050
0
SLANG_RAW("[ForceInline]\n")
31051
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31052
0
SLANG_RAW("int16_t4 unpackInt4x8ToInt16(uint packedValue)\n")
31053
0
SLANG_RAW("{\n")
31054
0
SLANG_RAW("    __target_switch\n")
31055
0
SLANG_RAW("    {\n")
31056
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"unpack_s8s16\";\n")
31057
0
SLANG_RAW("    case spirv:\n")
31058
0
SLANG_RAW("        return spirv_asm\n")
31059
0
SLANG_RAW("        {\n")
31060
0
SLANG_RAW("            %s8Vec = OpBitcast $$vector<int8_t, 4> $packedValue;\n")
31061
0
SLANG_RAW("            result:$$vector<int16_t, 4> = OpSConvert %s8Vec\n")
31062
0
SLANG_RAW("        };\n")
31063
0
SLANG_RAW("    default:\n")
31064
0
SLANG_RAW("        return int16_t4\n")
31065
0
SLANG_RAW("        (\n")
31066
0
SLANG_RAW("            __lsbAsInt16(packedValue),\n")
31067
0
SLANG_RAW("            __lsbAsInt16(packedValue >> 8U),\n")
31068
0
SLANG_RAW("            __lsbAsInt16(packedValue >> 16U),\n")
31069
0
SLANG_RAW("            int16_t(int8_t(packedValue >> 24U)),\n")
31070
0
SLANG_RAW("        );\n")
31071
0
SLANG_RAW("    }\n")
31072
0
SLANG_RAW("}\n")
31073
0
SLANG_RAW("\n")
31074
0
SLANG_RAW("/// Pack a vector of 4 unsigned 32/16 bit integers into a packed value of 4 8-bit integers, dropping unused bits.\n")
31075
0
SLANG_RAW("[__readNone]\n")
31076
0
SLANG_RAW("[ForceInline]\n")
31077
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31078
0
SLANG_RAW("uint packUint4x8(uint32_t4 unpackedValue)\n")
31079
0
SLANG_RAW("{\n")
31080
0
SLANG_RAW("    __target_switch\n")
31081
0
SLANG_RAW("    {\n")
31082
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_u8\";\n")
31083
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4xU8\";\n")
31084
0
SLANG_RAW("    default:\n")
31085
0
SLANG_RAW("        return __lsbAsUint32(unpackedValue.x)\n")
31086
0
SLANG_RAW("            | (__lsbAsUint32(unpackedValue.y) << 8U)\n")
31087
0
SLANG_RAW("            | (__lsbAsUint32(unpackedValue.z) << 16U)\n")
31088
0
SLANG_RAW("            | (unpackedValue.w << 24U);\n")
31089
0
SLANG_RAW("    }\n")
31090
0
SLANG_RAW("}\n")
31091
0
SLANG_RAW("\n")
31092
0
SLANG_RAW("[__readNone]\n")
31093
0
SLANG_RAW("[ForceInline]\n")
31094
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31095
0
SLANG_RAW("uint packUint4x8(uint16_t4 unpackedValue)\n")
31096
0
SLANG_RAW("{\n")
31097
0
SLANG_RAW("    __target_switch\n")
31098
0
SLANG_RAW("    {\n")
31099
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_u8\";\n")
31100
0
SLANG_RAW("    default:\n")
31101
0
SLANG_RAW("        return packUint4x8(uint32_t4(unpackedValue));\n")
31102
0
SLANG_RAW("    }\n")
31103
0
SLANG_RAW("}\n")
31104
0
SLANG_RAW("\n")
31105
0
SLANG_RAW("/// Pack a vector of 4 signed 32/16 bit integers into a packed value of 4 8-bit integers, dropping unused bits.\n")
31106
0
SLANG_RAW("[__readNone]\n")
31107
0
SLANG_RAW("[ForceInline]\n")
31108
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31109
0
SLANG_RAW("uint packInt4x8(int32_t4 unpackedValue)\n")
31110
0
SLANG_RAW("{\n")
31111
0
SLANG_RAW("    __target_switch\n")
31112
0
SLANG_RAW("    {\n")
31113
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_s8\";\n")
31114
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4xI8\";\n")
31115
0
SLANG_RAW("    default:\n")
31116
0
SLANG_RAW("        return packUint4x8(uint32_t4(unpackedValue));\n")
31117
0
SLANG_RAW("    }\n")
31118
0
SLANG_RAW("}\n")
31119
0
SLANG_RAW("\n")
31120
0
SLANG_RAW("[__readNone]\n")
31121
0
SLANG_RAW("[ForceInline]\n")
31122
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31123
0
SLANG_RAW("uint packInt4x8(int16_t4 unpackedValue)\n")
31124
0
SLANG_RAW("{\n")
31125
0
SLANG_RAW("    __target_switch\n")
31126
0
SLANG_RAW("    {\n")
31127
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_s8\";\n")
31128
0
SLANG_RAW("    default:\n")
31129
0
SLANG_RAW("        return packUint4x8(uint32_t4(unpackedValue));\n")
31130
0
SLANG_RAW("    }\n")
31131
0
SLANG_RAW("}\n")
31132
0
SLANG_RAW("\n")
31133
0
SLANG_RAW("/// Pack a vector of 4 signed 32/16 bit integers into a packed value of 4 8-bit integers,\n")
31134
0
SLANG_RAW("/// clamping each value to the range [0, 255] to ensure it fits within 8 bits.\n")
31135
0
SLANG_RAW("[__readNone]\n")
31136
0
SLANG_RAW("[ForceInline]\n")
31137
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31138
0
SLANG_RAW("uint packUint4x8Clamp(int32_t4 unpackedValue)\n")
31139
0
SLANG_RAW("{\n")
31140
0
SLANG_RAW("    __target_switch\n")
31141
0
SLANG_RAW("    {\n")
31142
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_clamp_u8\";\n")
31143
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4xU8Clamp(vec4<u32>($0))\";\n")
31144
0
SLANG_RAW("    default:\n")
31145
0
SLANG_RAW("        return packInt4x8(clamp(unpackedValue, 0, 255));\n")
31146
0
SLANG_RAW("    }\n")
31147
0
SLANG_RAW("}\n")
31148
0
SLANG_RAW("\n")
31149
0
SLANG_RAW("[__readNone]\n")
31150
0
SLANG_RAW("[ForceInline]\n")
31151
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31152
0
SLANG_RAW("uint packUint4x8Clamp(int16_t4 unpackedValue)\n")
31153
0
SLANG_RAW("{\n")
31154
0
SLANG_RAW("    __target_switch\n")
31155
0
SLANG_RAW("    {\n")
31156
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_clamp_u8\";\n")
31157
0
SLANG_RAW("    default:\n")
31158
0
SLANG_RAW("        return packInt4x8(clamp(unpackedValue, 0, 255));\n")
31159
0
SLANG_RAW("    }\n")
31160
0
SLANG_RAW("}\n")
31161
0
SLANG_RAW("\n")
31162
0
SLANG_RAW("/// Pack a vector of 4 signed 32/16 bit integers into a packed value of 4 8-bit integers,\n")
31163
0
SLANG_RAW("/// clamping each value to the range [-128, 127] to ensure it fits within 8 bits.\n")
31164
0
SLANG_RAW("[__readNone]\n")
31165
0
SLANG_RAW("[ForceInline]\n")
31166
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31167
0
SLANG_RAW("uint packInt4x8Clamp(int32_t4 unpackedValue)\n")
31168
0
SLANG_RAW("{\n")
31169
0
SLANG_RAW("    __target_switch\n")
31170
0
SLANG_RAW("    {\n")
31171
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_clamp_s8\";\n")
31172
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4xI8Clamp\";\n")
31173
0
SLANG_RAW("    default:\n")
31174
0
SLANG_RAW("        return packInt4x8(clamp(unpackedValue, -128, 127));\n")
31175
0
SLANG_RAW("    }\n")
31176
0
SLANG_RAW("}\n")
31177
0
SLANG_RAW("\n")
31178
0
SLANG_RAW("[__readNone]\n")
31179
0
SLANG_RAW("[ForceInline]\n")
31180
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31181
0
SLANG_RAW("uint packInt4x8Clamp(int16_t4 unpackedValue)\n")
31182
0
SLANG_RAW("{\n")
31183
0
SLANG_RAW("    __target_switch\n")
31184
0
SLANG_RAW("    {\n")
31185
0
SLANG_RAW("    case hlsl: __intrinsic_asm \"pack_clamp_s8\";\n")
31186
0
SLANG_RAW("    default:\n")
31187
0
SLANG_RAW("        return packInt4x8(clamp(unpackedValue, -128, 127));\n")
31188
0
SLANG_RAW("    }\n")
31189
0
SLANG_RAW("}\n")
31190
0
SLANG_RAW("\n")
31191
0
SLANG_RAW("//\n")
31192
0
SLANG_RAW("// Floating-point Pack/Unpack Intrinsics\n")
31193
0
SLANG_RAW("//\n")
31194
0
SLANG_RAW("\n")
31195
0
SLANG_RAW("// @public:\n")
31196
0
SLANG_RAW("\n")
31197
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into four 8-bit unsigned integers.\n")
31198
0
SLANG_RAW("/// Then, each 8-bit value is converted to a normalized single-precision\n")
31199
0
SLANG_RAW("/// floating-point value to generate a 4-component vector.\n")
31200
0
SLANG_RAW("[__readNone]\n")
31201
0
SLANG_RAW("[ForceInline]\n")
31202
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31203
0
SLANG_RAW("float4 unpackUnorm4x8ToFloat(uint packedValue)\n")
31204
0
SLANG_RAW("{\n")
31205
0
SLANG_RAW("    __target_switch\n")
31206
0
SLANG_RAW("    {\n")
31207
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackUnorm4x8\";\n")
31208
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_unorm4x8_to_float\";\n")
31209
0
SLANG_RAW("    case spirv:\n")
31210
0
SLANG_RAW("        return spirv_asm\n")
31211
0
SLANG_RAW("        {\n")
31212
0
SLANG_RAW("            result:$$float4 = OpExtInst glsl450 UnpackUnorm4x8 $packedValue;\n")
31213
0
SLANG_RAW("        };\n")
31214
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack4x8unorm\";\n")
31215
0
SLANG_RAW("    default:\n")
31216
0
SLANG_RAW("        uint4 unpackedIntegers = unpackUint4x8ToUint32(packedValue);\n")
31217
0
SLANG_RAW("        return float4(unpackedIntegers) / 255.0;\n")
31218
0
SLANG_RAW("    }\n")
31219
0
SLANG_RAW("}\n")
31220
0
SLANG_RAW("\n")
31221
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into four 8-bit unsigned integers.\n")
31222
0
SLANG_RAW("/// Then, each 8-bit value is converted to a normalized half-precision\n")
31223
0
SLANG_RAW("/// floating-point value to generate a 4-component vector.\n")
31224
0
SLANG_RAW("[__readNone]\n")
31225
0
SLANG_RAW("[ForceInline]\n")
31226
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31227
0
SLANG_RAW("half4 unpackUnorm4x8ToHalf(uint packedValue)\n")
31228
0
SLANG_RAW("{\n")
31229
0
SLANG_RAW("    __target_switch\n")
31230
0
SLANG_RAW("    {\n")
31231
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_unorm4x8_to_half\";\n")
31232
0
SLANG_RAW("    default:\n")
31233
0
SLANG_RAW("        return half4(unpackUnorm4x8ToFloat(packedValue));\n")
31234
0
SLANG_RAW("    }\n")
31235
0
SLANG_RAW("}\n")
31236
0
SLANG_RAW("\n")
31237
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into four 8-bit signed integers.\n")
31238
0
SLANG_RAW("/// Then, each 8-bit value is converted to a normalized single-precision\n")
31239
0
SLANG_RAW("/// floating-point value to generate a 4-component vector.\n")
31240
0
SLANG_RAW("[__readNone]\n")
31241
0
SLANG_RAW("[ForceInline]\n")
31242
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31243
0
SLANG_RAW("float4 unpackSnorm4x8ToFloat(uint packedValue)\n")
31244
0
SLANG_RAW("{\n")
31245
0
SLANG_RAW("    __target_switch\n")
31246
0
SLANG_RAW("    {\n")
31247
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackSnorm4x8\";\n")
31248
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_snorm4x8_to_float\";\n")
31249
0
SLANG_RAW("    case spirv:\n")
31250
0
SLANG_RAW("        return spirv_asm\n")
31251
0
SLANG_RAW("        {\n")
31252
0
SLANG_RAW("            result:$$float4 = OpExtInst glsl450 UnpackSnorm4x8 $packedValue;\n")
31253
0
SLANG_RAW("        };\n")
31254
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack4x8snorm\";\n")
31255
0
SLANG_RAW("    default:\n")
31256
0
SLANG_RAW("        int4 unpackedIntegers = unpackInt4x8ToInt32(packedValue);\n")
31257
0
SLANG_RAW("        return clamp(float4(unpackedIntegers) / 127.0, -1.0, 1.0);\n")
31258
0
SLANG_RAW("    }\n")
31259
0
SLANG_RAW("}\n")
31260
0
SLANG_RAW("\n")
31261
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into four 8-bit signed integers.\n")
31262
0
SLANG_RAW("/// Then, each 8-bit value is converted to a normalized half-precision\n")
31263
0
SLANG_RAW("/// floating-point value to generate a 4-component vector.\n")
31264
0
SLANG_RAW("[__readNone]\n")
31265
0
SLANG_RAW("[ForceInline]\n")
31266
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31267
0
SLANG_RAW("half4 unpackSnorm4x8ToHalf(uint packedValue)\n")
31268
0
SLANG_RAW("{\n")
31269
0
SLANG_RAW("    __target_switch\n")
31270
0
SLANG_RAW("    {\n")
31271
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_snorm4x8_to_half\";\n")
31272
0
SLANG_RAW("    default:\n")
31273
0
SLANG_RAW("        return half4(unpackSnorm4x8ToFloat(packedValue));\n")
31274
0
SLANG_RAW("    }\n")
31275
0
SLANG_RAW("}\n")
31276
0
SLANG_RAW("\n")
31277
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit usigned integers.\n")
31278
0
SLANG_RAW("/// Then, each 16-bit value is converted to a normalized single-precision\n")
31279
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31280
0
SLANG_RAW("[__readNone]\n")
31281
0
SLANG_RAW("[ForceInline]\n")
31282
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31283
0
SLANG_RAW("float2 unpackUnorm2x16ToFloat(uint packedValue)\n")
31284
0
SLANG_RAW("{\n")
31285
0
SLANG_RAW("    __target_switch\n")
31286
0
SLANG_RAW("    {\n")
31287
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackUnorm2x16\";\n")
31288
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_unorm2x16_to_float\";\n")
31289
0
SLANG_RAW("    case spirv:\n")
31290
0
SLANG_RAW("        return spirv_asm\n")
31291
0
SLANG_RAW("        {\n")
31292
0
SLANG_RAW("            result:$$float2 = OpExtInst glsl450 UnpackUnorm2x16 $packedValue;\n")
31293
0
SLANG_RAW("        };\n")
31294
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack2x16unorm\";\n")
31295
0
SLANG_RAW("    default:\n")
31296
0
SLANG_RAW("        uint2 unpackedIntegers = __unpackUint2x16ToUint32(packedValue);\n")
31297
0
SLANG_RAW("        return float2(unpackedIntegers) / 65535.0;\n")
31298
0
SLANG_RAW("    }\n")
31299
0
SLANG_RAW("}\n")
31300
0
SLANG_RAW("\n")
31301
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit usigned integers.\n")
31302
0
SLANG_RAW("/// Then, each 16-bit value is converted to a normalized half-precision\n")
31303
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31304
0
SLANG_RAW("[__readNone]\n")
31305
0
SLANG_RAW("[ForceInline]\n")
31306
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31307
0
SLANG_RAW("half2 unpackUnorm2x16ToHalf(uint packedValue)\n")
31308
0
SLANG_RAW("{\n")
31309
0
SLANG_RAW("    __target_switch\n")
31310
0
SLANG_RAW("    {\n")
31311
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_unorm2x16_to_half\";\n")
31312
0
SLANG_RAW("    default:\n")
31313
0
SLANG_RAW("        return half2(unpackUnorm2x16ToFloat(packedValue));\n")
31314
0
SLANG_RAW("    }\n")
31315
0
SLANG_RAW("}\n")
31316
0
SLANG_RAW("\n")
31317
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit signed integers.\n")
31318
0
SLANG_RAW("/// Then, each 16-bit value is converted to a normalized single-precision\n")
31319
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31320
0
SLANG_RAW("[__readNone]\n")
31321
0
SLANG_RAW("[ForceInline]\n")
31322
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31323
0
SLANG_RAW("float2 unpackSnorm2x16ToFloat(uint packedValue)\n")
31324
0
SLANG_RAW("{\n")
31325
0
SLANG_RAW("    __target_switch\n")
31326
0
SLANG_RAW("    {\n")
31327
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackSnorm2x16\";\n")
31328
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_snorm2x16_to_float\";\n")
31329
0
SLANG_RAW("    case spirv:\n")
31330
0
SLANG_RAW("        return spirv_asm\n")
31331
0
SLANG_RAW("        {\n")
31332
0
SLANG_RAW("            result:$$float2 = OpExtInst glsl450 UnpackSnorm2x16 $packedValue;\n")
31333
0
SLANG_RAW("        };\n")
31334
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack2x16snorm\";\n")
31335
0
SLANG_RAW("    default:\n")
31336
0
SLANG_RAW("        int2 unpackedIntegers = __unpackInt2x16ToInt32(packedValue);\n")
31337
0
SLANG_RAW("        return clamp(float2(unpackedIntegers) / 32767.0, -1.0, 1.0);\n")
31338
0
SLANG_RAW("    }\n")
31339
0
SLANG_RAW("}\n")
31340
0
SLANG_RAW("\n")
31341
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit signed integers.\n")
31342
0
SLANG_RAW("/// Then, each 16-bit value is converted to a normalized half-precision\n")
31343
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31344
0
SLANG_RAW("[__readNone]\n")
31345
0
SLANG_RAW("[ForceInline]\n")
31346
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31347
0
SLANG_RAW("half2 unpackSnorm2x16ToHalf(uint packedValue)\n")
31348
0
SLANG_RAW("{\n")
31349
0
SLANG_RAW("    __target_switch\n")
31350
0
SLANG_RAW("    {\n")
31351
0
SLANG_RAW("    case metal: __intrinsic_asm \"unpack_snorm2x16_to_half\";\n")
31352
0
SLANG_RAW("    default:\n")
31353
0
SLANG_RAW("        return half2(unpackSnorm2x16ToFloat(packedValue));\n")
31354
0
SLANG_RAW("    }\n")
31355
0
SLANG_RAW("}\n")
31356
0
SLANG_RAW("\n")
31357
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit signed integers.\n")
31358
0
SLANG_RAW("/// Then, each 16-bit value is converted to an IEEE-754 binary16 single-precision\n")
31359
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31360
0
SLANG_RAW("[__readNone]\n")
31361
0
SLANG_RAW("[ForceInline]\n")
31362
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31363
0
SLANG_RAW("float2 unpackHalf2x16ToFloat(uint packedValue)\n")
31364
0
SLANG_RAW("{\n")
31365
0
SLANG_RAW("    __target_switch\n")
31366
0
SLANG_RAW("    {\n")
31367
0
SLANG_RAW("    case glsl: __intrinsic_asm \"unpackHalf2x16\";\n")
31368
0
SLANG_RAW("    case spirv:\n")
31369
0
SLANG_RAW("        return spirv_asm\n")
31370
0
SLANG_RAW("        {\n")
31371
0
SLANG_RAW("            result:$$float2 = OpExtInst glsl450 UnpackHalf2x16 $packedValue;\n")
31372
0
SLANG_RAW("        };\n")
31373
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"unpack2x16float\";\n")
31374
0
SLANG_RAW("    default:\n")
31375
0
SLANG_RAW("        uint2 unpackedIntegers = __unpackUint2x16ToUint32(packedValue);\n")
31376
0
SLANG_RAW("        return f16tof32(unpackedIntegers);\n")
31377
0
SLANG_RAW("    }\n")
31378
0
SLANG_RAW("}\n")
31379
0
SLANG_RAW("\n")
31380
0
SLANG_RAW("/// Unpack a 32-bit unsigned integer into two 16-bit signed integers.\n")
31381
0
SLANG_RAW("/// Then, each 16-bit value is converted to an IEEE-754 binary16 half-precision\n")
31382
0
SLANG_RAW("/// floating-point value to generate a 2-component vector.\n")
31383
0
SLANG_RAW("[__readNone]\n")
31384
0
SLANG_RAW("[ForceInline]\n")
31385
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31386
0
SLANG_RAW("half2 unpackHalf2x16ToHalf(uint packedValue)\n")
31387
0
SLANG_RAW("{\n")
31388
0
SLANG_RAW("    return half2(unpackHalf2x16ToFloat(packedValue));\n")
31389
0
SLANG_RAW("}\n")
31390
0
SLANG_RAW("\n")
31391
0
SLANG_RAW("/// Convert a 4-component vector of normalized unsigned single/half-precision floating-point\n")
31392
0
SLANG_RAW("/// values to four 8-bit integer values, then pack these 8-bit values into a\n")
31393
0
SLANG_RAW("/// 32-bit unsigned integer.\n")
31394
0
SLANG_RAW("[__readNone]\n")
31395
0
SLANG_RAW("[ForceInline]\n")
31396
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31397
0
SLANG_RAW("uint packUnorm4x8(float4 unpackedValue)\n")
31398
0
SLANG_RAW("{\n")
31399
0
SLANG_RAW("    __target_switch\n")
31400
0
SLANG_RAW("    {\n")
31401
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packUnorm4x8\";\n")
31402
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_float_to_unorm4x8\";\n")
31403
0
SLANG_RAW("    case spirv:\n")
31404
0
SLANG_RAW("        return spirv_asm\n")
31405
0
SLANG_RAW("        {\n")
31406
0
SLANG_RAW("            result:$$uint = OpExtInst glsl450 PackUnorm4x8 $unpackedValue\n")
31407
0
SLANG_RAW("        };\n")
31408
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4x8unorm\";\n")
31409
0
SLANG_RAW("    default:\n")
31410
0
SLANG_RAW("        uint4 values = uint4(round(saturate(unpackedValue) * 255.0));\n")
31411
0
SLANG_RAW("        return packUint4x8(values);\n")
31412
0
SLANG_RAW("    }\n")
31413
0
SLANG_RAW("}\n")
31414
0
SLANG_RAW("\n")
31415
0
SLANG_RAW("[__readNone]\n")
31416
0
SLANG_RAW("[ForceInline]\n")
31417
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31418
0
SLANG_RAW("uint packUnorm4x8(half4 unpackedValue)\n")
31419
0
SLANG_RAW("{\n")
31420
0
SLANG_RAW("    __target_switch\n")
31421
0
SLANG_RAW("    {\n")
31422
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_half_to_unorm4x8\";\n")
31423
0
SLANG_RAW("    default:\n")
31424
0
SLANG_RAW("        return packUnorm4x8(float4(unpackedValue));\n")
31425
0
SLANG_RAW("    }\n")
31426
0
SLANG_RAW("}\n")
31427
0
SLANG_RAW("\n")
31428
0
SLANG_RAW("/// Convert a 4-component vector of normalized signed single/half-precision floating-point\n")
31429
0
SLANG_RAW("/// values to four 8-bit integer values, then pack these 8-bit values into a\n")
31430
0
SLANG_RAW("/// 32-bit unsigned integer.\n")
31431
0
SLANG_RAW("[__readNone]\n")
31432
0
SLANG_RAW("[ForceInline]\n")
31433
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31434
0
SLANG_RAW("uint packSnorm4x8(float4 unpackedValue)\n")
31435
0
SLANG_RAW("{\n")
31436
0
SLANG_RAW("    __target_switch\n")
31437
0
SLANG_RAW("    {\n")
31438
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packSnorm4x8\";\n")
31439
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_float_to_snorm4x8\";\n")
31440
0
SLANG_RAW("    case spirv:\n")
31441
0
SLANG_RAW("        return spirv_asm\n")
31442
0
SLANG_RAW("        {\n")
31443
0
SLANG_RAW("            result:$$uint = OpExtInst glsl450 PackSnorm4x8 $unpackedValue\n")
31444
0
SLANG_RAW("        };\n")
31445
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack4x8snorm\";\n")
31446
0
SLANG_RAW("    default:\n")
31447
0
SLANG_RAW("        int4 values = int4(round(clamp(unpackedValue, -1.0, 1.0) * 127.0)) & 0xFF;\n")
31448
0
SLANG_RAW("        return packInt4x8(values);\n")
31449
0
SLANG_RAW("    }\n")
31450
0
SLANG_RAW("}\n")
31451
0
SLANG_RAW("\n")
31452
0
SLANG_RAW("[__readNone]\n")
31453
0
SLANG_RAW("[ForceInline]\n")
31454
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31455
0
SLANG_RAW("uint packSnorm4x8(half4 unpackedValue)\n")
31456
0
SLANG_RAW("{\n")
31457
0
SLANG_RAW("    __target_switch\n")
31458
0
SLANG_RAW("    {\n")
31459
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_half_to_snorm4x8\";\n")
31460
0
SLANG_RAW("    default:\n")
31461
0
SLANG_RAW("        return packSnorm4x8(float4(unpackedValue));\n")
31462
0
SLANG_RAW("    }\n")
31463
0
SLANG_RAW("}\n")
31464
0
SLANG_RAW("\n")
31465
0
SLANG_RAW("/// Convert a 2-component vector of normalized unsigned single/half-precision floating-point\n")
31466
0
SLANG_RAW("/// values to two 16-bit integer values, then pack these 16-bit values into a\n")
31467
0
SLANG_RAW("/// 32-bit unsigned integer.\n")
31468
0
SLANG_RAW("[__readNone]\n")
31469
0
SLANG_RAW("[ForceInline]\n")
31470
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31471
0
SLANG_RAW("uint packUnorm2x16(float2 unpackedValue)\n")
31472
0
SLANG_RAW("{\n")
31473
0
SLANG_RAW("    __target_switch\n")
31474
0
SLANG_RAW("    {\n")
31475
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packUnorm2x16\";\n")
31476
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_float_to_unorm2x16\";\n")
31477
0
SLANG_RAW("    case spirv:\n")
31478
0
SLANG_RAW("        return spirv_asm\n")
31479
0
SLANG_RAW("        {\n")
31480
0
SLANG_RAW("            result:$$uint = OpExtInst glsl450 PackUnorm2x16 $unpackedValue;\n")
31481
0
SLANG_RAW("        };\n")
31482
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack2x16unorm\";\n")
31483
0
SLANG_RAW("    default:\n")
31484
0
SLANG_RAW("        uint2 values = uint2(round(saturate(unpackedValue) * 65535.0));\n")
31485
0
SLANG_RAW("        return __packUint2x16(values);\n")
31486
0
SLANG_RAW("    }\n")
31487
0
SLANG_RAW("}\n")
31488
0
SLANG_RAW("\n")
31489
0
SLANG_RAW("[__readNone]\n")
31490
0
SLANG_RAW("[ForceInline]\n")
31491
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31492
0
SLANG_RAW("uint packUnorm2x16(half2 unpackedValue)\n")
31493
0
SLANG_RAW("{\n")
31494
0
SLANG_RAW("    __target_switch\n")
31495
0
SLANG_RAW("    {\n")
31496
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_half_to_unorm2x16\";\n")
31497
0
SLANG_RAW("    default:\n")
31498
0
SLANG_RAW("        return packUnorm2x16(float2(unpackedValue));\n")
31499
0
SLANG_RAW("    }\n")
31500
0
SLANG_RAW("}\n")
31501
0
SLANG_RAW("\n")
31502
0
SLANG_RAW("/// Convert a 2-component vector of normalized signed single/half-precision floating-point\n")
31503
0
SLANG_RAW("/// values to two 16-bit integer values, then pack these 16-bit values into a\n")
31504
0
SLANG_RAW("/// 32-bit unsigned integer.\n")
31505
0
SLANG_RAW("[__readNone]\n")
31506
0
SLANG_RAW("[ForceInline]\n")
31507
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31508
0
SLANG_RAW("uint packSnorm2x16(float2 unpackedValue)\n")
31509
0
SLANG_RAW("{\n")
31510
0
SLANG_RAW("    __target_switch\n")
31511
0
SLANG_RAW("    {\n")
31512
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packSnorm2x16\";\n")
31513
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_float_to_snorm2x16\";\n")
31514
0
SLANG_RAW("    case spirv:\n")
31515
0
SLANG_RAW("        return spirv_asm\n")
31516
0
SLANG_RAW("        {\n")
31517
0
SLANG_RAW("            result:$$uint = OpExtInst glsl450 PackSnorm2x16 $unpackedValue;\n")
31518
0
SLANG_RAW("        };\n")
31519
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack2x16snorm\";\n")
31520
0
SLANG_RAW("    default:\n")
31521
0
SLANG_RAW("        int2 values = int2(round(clamp(unpackedValue, -1.0, 1.0) * 32767.0)) & 0xFFFF;\n")
31522
0
SLANG_RAW("        return __packInt2x16(values);\n")
31523
0
SLANG_RAW("    }\n")
31524
0
SLANG_RAW("}\n")
31525
0
SLANG_RAW("\n")
31526
0
SLANG_RAW("[__readNone]\n")
31527
0
SLANG_RAW("[ForceInline]\n")
31528
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31529
0
SLANG_RAW("uint packSnorm2x16(half2 unpackedValue)\n")
31530
0
SLANG_RAW("{\n")
31531
0
SLANG_RAW("    __target_switch\n")
31532
0
SLANG_RAW("    {\n")
31533
0
SLANG_RAW("    case metal: __intrinsic_asm \"pack_half_to_snorm2x16\";\n")
31534
0
SLANG_RAW("    default:\n")
31535
0
SLANG_RAW("        return packSnorm2x16(float2(unpackedValue));\n")
31536
0
SLANG_RAW("    }\n")
31537
0
SLANG_RAW("}\n")
31538
0
SLANG_RAW("\n")
31539
0
SLANG_RAW("/// Convert a 2-component vector of IEEE-754 binary16 single/half-precision floating-point\n")
31540
0
SLANG_RAW("/// values to two 16-bit integer values, then pack these 16-bit values into a\n")
31541
0
SLANG_RAW("/// 32-bit unsigned integer.\n")
31542
0
SLANG_RAW("[__readNone]\n")
31543
0
SLANG_RAW("[ForceInline]\n")
31544
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31545
0
SLANG_RAW("uint packHalf2x16(float2 unpackedValue)\n")
31546
0
SLANG_RAW("{\n")
31547
0
SLANG_RAW("    __target_switch\n")
31548
0
SLANG_RAW("    {\n")
31549
0
SLANG_RAW("    case glsl: __intrinsic_asm \"packHalf2x16\";\n")
31550
0
SLANG_RAW("    case spirv:\n")
31551
0
SLANG_RAW("        return spirv_asm\n")
31552
0
SLANG_RAW("        {\n")
31553
0
SLANG_RAW("            result:$$uint = OpExtInst glsl450 PackHalf2x16 $unpackedValue;\n")
31554
0
SLANG_RAW("        };\n")
31555
0
SLANG_RAW("    case wgsl: __intrinsic_asm \"pack2x16float\";\n")
31556
0
SLANG_RAW("    default:\n")
31557
0
SLANG_RAW("        uint2 values = f32tof16(unpackedValue);\n")
31558
0
SLANG_RAW("        return __packUint2x16(values);\n")
31559
0
SLANG_RAW("    }\n")
31560
0
SLANG_RAW("}\n")
31561
0
SLANG_RAW("\n")
31562
0
SLANG_RAW("[__readNone]\n")
31563
0
SLANG_RAW("[ForceInline]\n")
31564
0
SLANG_RAW("[require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, pack_vector)]\n")
31565
0
SLANG_RAW("uint packHalf2x16(half2 unpackedValue)\n")
31566
0
SLANG_RAW("{\n")
31567
0
SLANG_RAW("    return packHalf2x16(float2(unpackedValue));\n")
31568
0
SLANG_RAW("}\n")
31569
0
SLANG_RAW("\n")
31570
0
SLANG_RAW("[require(spirv)]\n")
31571
0
SLANG_RAW("void InterlockedAddF16Emulated(half* dest, half value, out half originalValue)\n")
31572
0
SLANG_RAW("{\n")
31573
0
SLANG_RAW("    let buf = (half2*)(dest);\n")
31574
0
SLANG_RAW("    uint64_t byteAddress = (uint64_t)dest;\n")
31575
0
SLANG_RAW("    if ((byteAddress & 3) == 0)\n")
31576
0
SLANG_RAW("    {\n")
31577
0
SLANG_RAW("        originalValue = __atomic_add(*buf, half2(value, half(0.0))).x;\n")
31578
0
SLANG_RAW("    }\n")
31579
0
SLANG_RAW("    else\n")
31580
0
SLANG_RAW("    {\n")
31581
0
SLANG_RAW("        originalValue = __atomic_add(*buf, half2(half(0.0), value)).y;\n")
31582
0
SLANG_RAW("    }\n")
31583
0
SLANG_RAW("}\n")
31584
0
SLANG_RAW("\n")
31585
0
SLANG_RAW("[require(spirv)]\n")
31586
0
SLANG_RAW("void InterlockedAddF16x2(half2* dest, half2 value, out half2 originalValue)\n")
31587
0
SLANG_RAW("{\n")
31588
0
SLANG_RAW("    originalValue = __atomic_add(*dest, value);\n")
31589
0
SLANG_RAW("}\n")